nsuserdefaults

Problems with NSString inside viewWillDisappear

空扰寡人 提交于 2019-12-12 04:54:48
问题 I am battling with this piece of code for days now, I really would appreciate your insight. So here it is... fileName which is declared in my .h file as NSString *fileName; and later as @property (nonatomic, copy) NSString *fileName; is not accessible inside viewWillDisappear . It just shows up as nil object, or some weird value when I debug. When I debug, my console show this msg: Printing description of fileName: FileNumber1 When I reach to viewWillDisappear my console shows this: Printing

Attempt to set a non-property-list object as an NSUserDefaults

醉酒当歌 提交于 2019-12-12 04:25:37
问题 I thought I knew what was causing this error, but I can't seem to figure out what I did wrong. Here is the full error message I am getting: Attempt to set a non-property-list object ( "<BC_Person: 0x8f3c140>" ) as an NSUserDefaults value for key personDataArray I have a Person class that I think is conforming to the NSCoding protocol, where I have both of these methods in my person class: - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:self.personsName forKey:@"BCPersonsName"];

How to save a multidimensional array to UserDefaults

烂漫一生 提交于 2019-12-12 03:43:20
问题 Have created an Array like this in Swift var MyArray: [String:[String:[Int]]] = [ "xx": ["x1": [1, 2, 3], "x2": [4, 5, 6], "x3": [7, 8, 9]], "yy": ["y1": [10, 11, 12], "y2": [13, 14, 15], "y3": [16, 17, 18]] ] And I wonder how to save this to the UserDefaults 回答1: As @Eric mentioned in comment this is not a multidimensional array it is nested dictionary, so you can set it using set(_:forKey:) and get dictionary using dictionary(forKey:). Save dictionary in UserDefaults let defaults =

If let clause when getting from NSUserDefaults()

痞子三分冷 提交于 2019-12-12 03:35:51
问题 I'm trying to manage a variable like this: var isFinished: Bool { get { return NSUserDefaults.standardUserDefaults().boolForKey("isFinished") } set { NSUserDefaults.standardUserDefaults().setBool(newValue, forKey: "isFinished") NSUserDefaults.standardUserDefaults().synchronize() } } This works, however, I'm trying to make it more safe by using an if let when getting: var isFinished: Bool { get { if let isFinished = NSUserDefaults.standardUserDefaults().boolForKey("isFinished") as? Bool {

App Delegate weird error when trying to add element to NSUserDefaults

孤者浪人 提交于 2019-12-12 03:24:18
问题 I've got a really weird error while running my app on Xcode 7 (Swift 2) that shows a "Thread 1: signal SIGABRT" running error message in the App Delegate class of my app. However I've actually already got this "Thread 1: signal SIGABRT" running error message in the App Delegate class lots of times, mainly when deleting an outlet reference in my code and forgetting to also delete it from storyboard. But that's certainly the first time I've got this same error when trying to make the command:

how to don't get a nil value from NSUserDefaults in ViewDidLoad

萝らか妹 提交于 2019-12-12 02:54:25
问题 I have a case where when my viewControler starts in viewDidLoad I have to load some data using NSUserDefaults.standardUserDefaults() which doesn't exist in this monent. This data are saved when I tap send Button in the same viewController and I need this data when I open this viewController again. Now it looks like that: var orderHistory = [String:String]() vievDidLoad(){ let userDefault = NSUserDefaults.standardUserDefaults() let orderHistory = userDefault.objectForKey("orderHistory") if

Ho to refresh view and tableview, and checkmark a default setting cell on load?

ε祈祈猫儿з 提交于 2019-12-12 02:48:52
问题 I'm currently setting up the "Settings/preferences" side of my first app in iOS. i currently have NSUserdefaults setup so that the app remembers the users preferences. I have 2 questions: Firstly, once a particular cell has been selected it is checkmarked and saved as a default(works), but when i move back to the main setting tableview, i have a label on the cell that it links with that needs to update but doesn't until i move back further to main page, then load settings again. a way to

Defaults too complex to compile with basic '+' operator

最后都变了- 提交于 2019-12-12 02:16:15
问题 func updateTotalScore() -> Int { var totalScoreDefault = NSUserDefaults.standardUserDefaults() var highScoreAB1 = defaults.integerForKey("highScoreAB1") var highScoreAB2 = defaults.integerForKey("highScoreAB2") var highScoreAB3 = defaults.integerForKey("highScoreAB3") var highScoreAB4 = defaults.integerForKey("highScoreAB4") var highScoreAB5 = defaults.integerForKey("HighScoreAB5") var highScoreAB6 = defaults.integerForKey("highScoreAB6") var highScoreAB7 = defaults.integerForKey(

Speed: XML vs. NSUserDefaults

心不动则不痛 提交于 2019-12-12 02:12:48
问题 I'm attempting to load and store (read AND write) a library of song information, and I don't know which method of storage would be more efficient. Initially I stored an NSArray that I'd created to a NSUserDefault, which allows for read/write access. However, after looking into how iTunes stores its library information, I've considered reading and writing from an XML file. Which would be easier to implement and more effective speed/memory usage wise? Any help would be greatly appreciated.. 回答1

Saving Facebook access_token in NSUserDefaults on iOS

这一生的挚爱 提交于 2019-12-12 02:08:52
问题 iOS beginner here. I'm using the following code to save my facebook accessToken and expirationDate in NSUserDefaults: facebook = [[Facebook alloc] initWithAppId:@"225083222506272"]; [facebook authorize:nil delegate:self]; NSString *access=[facebook accessToken]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:access, @"accessToken",[facebook expirationDate], @"expirationDate",nil]; [defaults