nsuserdefaults

Where are user defaults plist files stored in iOS8?

痴心易碎 提交于 2020-01-31 09:30:19
问题 I can't find preferences .plist file, because Preferences folder is empty. To get Library folder I use: println(NSSearchPathForDirectoriesInDomains(.LibraryDirectory, .UserDomainMask, true)[0]) Xcode 6 beta 5, iOS Simulator 回答1: The folder hierarchy has changed under iOS8. All preferences are now stored under the common /Library/Preferences folder. Notice, this is not the Library folder under your app's container, it's the general Library folder. For the simulator, the exact folder is: ~

NSUserDefaults in Swift - implementing type safety

拈花ヽ惹草 提交于 2020-01-30 17:45:09
问题 One of the things that bugs me about Swift and Cocoa together is working with NSUserDefaults, because there is no type information and it is always necessary to cast the result of objectForKey to what you are expecting to get. It is unsafe and impractical. I decided to tackle this problem, making NSUserDefaults more practical in Swift-land, and hopefully learning something along the way. Here were my goals in the beginning: Complete type safety: each key has one type associated with it. When

NSUserDefaults in Swift - implementing type safety

回眸只為那壹抹淺笑 提交于 2020-01-30 17:44:45
问题 One of the things that bugs me about Swift and Cocoa together is working with NSUserDefaults, because there is no type information and it is always necessary to cast the result of objectForKey to what you are expecting to get. It is unsafe and impractical. I decided to tackle this problem, making NSUserDefaults more practical in Swift-land, and hopefully learning something along the way. Here were my goals in the beginning: Complete type safety: each key has one type associated with it. When

How to remove all data by a suite name from UserDefaults in Swift?

让人想犯罪 __ 提交于 2020-01-30 12:13:43
问题 I have created user defaults with names below, let prefs1 = UserDefaults.init(suiteName: "UserAccount") let prefs2 = UserDefaults.init(suiteName: "UserInfo") Then I have added some values to those suites. i.e. prefs1.set(true, forKey: "Key1") prefs1.set(true, forKey: "Key2") prefs2.set(false, forKey: "Key1") prefs2.set(false, forKey: "Key2") Now, I want to remove the prefs1 (i.e. name "UserAccount"), but not prefs2 . I tried, UserDefaults.standard.removePersistentDomain(forName: "UserAccount"

Why use registerDefaults: instead of setValue:forKey:?

▼魔方 西西 提交于 2020-01-29 04:05:14
问题 When I'm setting up the default preferences for my app, I'm doing the following: 1) Reading Root.plist from inside Settings.bundle into a dictionary. 2) I test if a preference is set, and if not I'm registering my defaults dictionary via [NSUserDefaults standardUserDefaults] registerDefaults:] Problem is, defaults registered with registerDefaults: do not go to the persistent store, so if the user never changes their preferences I am reading my default preferences and registering them with

Saving NSManagedObject in NSUserDefaults

你说的曾经没有我的故事 提交于 2020-01-25 06:57:05
问题 Hello everyone (sorry for my bad english, I'm French), I'm trying to put my NSManagedObject into NSUserDefaults to retrieve it with its relationships. Basically I used NSCoding and I had implemented the required method, but because it's NSManaged objects, the signature of the init method it's : init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?). The message is "'NSInvalidArgumentException', reason: 'Illegal attempt to establish a relationship

Using NSUserDefaults to add a 24hour countdown timer in SWIFT

我怕爱的太早我们不能终老 提交于 2020-01-23 20:57:45
问题 I am trying to add a timer for when a user clicks a button it starts a timer for 24 hours and disables the button for the next 24 hours. After that it is enabled again. There is a few answers out there for things similar but not 100% useful for doing it in SWIFT. The main problem I am having is that I want this to be specific for each user. So 24 hours for every click on that one user. So for example: If I 'like' something then you want be able to 'like' that particular thing again for 24

How to save and retrieve NSObject class using NSUserDafaults in iOS

巧了我就是萌 提交于 2020-01-21 16:14:42
问题 Hi I want to save and retrieve NSObject class using NSUserDefaults for that I wrote below code but I am getting exception like below Terminating app due to uncaught exception ' NSInvalidArgumentException ', reason: 'Attempt to insert non-property list object for key DATA' For saving :- SavingBean*savingbean = [[SavingBean alloc]init]; [savingbean savingData:userName.text :passWord.text]; NSUserDefaults * defaults = [[NSUserDefaults alloc]init]; [defaults setObject:savingbean forKey:@"DATA"];

How to save and retrieve NSObject class using NSUserDafaults in iOS

[亡魂溺海] 提交于 2020-01-21 16:14:17
问题 Hi I want to save and retrieve NSObject class using NSUserDefaults for that I wrote below code but I am getting exception like below Terminating app due to uncaught exception ' NSInvalidArgumentException ', reason: 'Attempt to insert non-property list object for key DATA' For saving :- SavingBean*savingbean = [[SavingBean alloc]init]; [savingbean savingData:userName.text :passWord.text]; NSUserDefaults * defaults = [[NSUserDefaults alloc]init]; [defaults setObject:savingbean forKey:@"DATA"];

How to auto clear NSUserDefault values in swift? [duplicate]

跟風遠走 提交于 2020-01-19 23:24:29
问题 This question already has answers here : Delete all keys from a NSUserDefaults dictionary iOS (15 answers) Closed 3 years ago . How can I auto clear the nsuserdefault values in swift? I have already tried this but it doesn't work for me... [[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary] forName:[[NSBundle mainBundle] bundleIdentifier]]; 回答1: check how many keys are already stored print(NSUserDefaults.standardUserDefaults().dictionaryRepresentation().keys