nsuserdefaults

Swift mutable dictionary being treated as immutable

自作多情 提交于 2019-12-23 20:31:47
问题 I am trying to implement In App Purchases, and I am tracking which purchases a user has purchased via NSUserDefaults . I have a function that sets the values of each purchase, but when it runs, I get an error saying that I am mutating the dictionary of purchase values even though the dictionary is declared with a var instead of a let and is an NSMutableDictionary . Sometimes it does work, but most of the time it doesn't. I get a few warnings about declaring my variables with let instead of

NSUserDefaults or something else when storing large arrays?

若如初见. 提交于 2019-12-23 19:40:51
问题 I have an app that reads JSON into in-memory objects. I have one object representing the User and then an array of custom objects. This array is ususally 20-50 objects but can be up to 7-800 in rare cases. I've read some threads about this, but find it hard to pick, since all i want to do is cache this locally, nothing more, so that i can fetch less from the server. I can see three solutions: NSUserDefaults . Not sure how app performance is affected by large array CoreData / MagicalRecord .

NSUserDefaults and sandboxing under Lion

风格不统一 提交于 2019-12-23 13:58:29
问题 Moving one of my projects to support sandboxing as per Apple's requirements. I use UserDefaults like so: [[NSUserDefaults standardUserDefaults] setObject:@(myNumber) forKey:myNumberKey]; [[NSUserDefaults standardUserDefaults] synchronize]; Everything works as expected until I enable sandboxing. If I have sandboxing enabled the app creates a lock file in it's sandbox directory ( .plist.lockfile) and doesn't create an actual .plist file. What am I doing wrong and how do I store my settings in

How often are NSUserDefaults synchronised?

大兔子大兔子 提交于 2019-12-23 10:26:23
问题 The documentation for NSUserDefaults says that the synchronise method is called periodically but does not mention how frequently. 10 minutes of Google searches did not reveal anything. How frequently is the synchronise method called? 回答1: This is an implementation detail which is not disclosed (probably it isn't even a constant time interval). However, you can find it out yourself by performing a method swizzling on - [NSUserDefaults synchronize] and changing its implementation so that it

NSUrl is not stored as absolutestring in NSUserDefault

孤街浪徒 提交于 2019-12-23 09:09:10
问题 I am referring Previous Post for storing NSURL of iPod Library in NSUserDefault. But it is not stored in NSUserDefault after application is closed. I am using other NSStrings to store in NSUserDefaults which is perfectly done, But when i store NSUrl as absolute string.. it does not stores the value. What could be the reason?? EDIT Following code i am using to save NSUserDefault Value: currentItem = [collection.items objectAtIndex:songCount]; songURL = [currentItem valueForProperty

iPhone - upgrading from old app preferences

三世轮回 提交于 2019-12-23 05:48:46
问题 If I build a 1.0 app with 2 strings in the defaults, using registerDefaults . And in a 2.0 version, I decide to remove the first old string, and move the second one (changing its key string) with a new third one into an array. How may I deal with this and how to deal with the changes that could have been made to the content through versions. 1.0 Prefs should be StringKey someValue DateKey 10/10/2010 1.1 Prefs should be StringKey someValue DateKey 2010/10/10 2.0 Prefs should be Array Item0 is

Storing a dictionary of Int and Array in NSUserDefaults error

旧城冷巷雨未停 提交于 2019-12-23 05:30:52
问题 What I know so far about the subject: I understand that there are only certain data types that you can store into NSUserDefaults: The NSUserDefaults class provides convenience methods for accessing common types such as floats , doubles , integers , Booleans , and URLs . A default object must be a property list, that is, an instance of (or for collections a combination of instances of): NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. If you want to store any other type of object,

Show a View on First Launch Only - Swift 3

我的未来我决定 提交于 2019-12-23 05:08:27
问题 I am implementing a Terms & Conditions view into my app and the user has to accept them to proceed, then when they do accept them, they no longer have to go through the Terms & Conditions view. I followed a tutorial on how to integrate UserDefaults and store the value locally if someone does accept the terms. However I am stuck with implementing it into the root view controller. Specifically stuck on my viewDidAppear function. What goes in the if and else statements? class

NSUserDefaults not working with UITableView in Swift

空扰寡人 提交于 2019-12-23 04:54:31
问题 I'm relatively new to Swift and am making a basic homework diary app. What I have so far is a UITableView embedded in a navigation controller which is embedded in a tab bar controller. I have successfully managed to implement a pull to refresh, adding data in a UIAlertView and populating the table with this data after the refresh. I need persistent data for this app and I heard that NSUserDefaults is the best way to do that, but it's not working for me. I can see that it is adding to the

vs own Plist

假装没事ソ 提交于 2019-12-23 03:26:23
问题 In my past projects I always made a NSObject-HelperClass which interacts with a selfmade-Plist. Now i hear I can use [NSUserDefaults standardUserDefaults] and have also my dictionary. So why should I use UserDefaults instead of my own NSObject which massages the plist? cheers endo 回答1: NSUserDefaults is a convenient way to store some preferences and the current state of the application (ex: "remember me" checkbox set to yes or no). You should only use it for this kind of data. You can also