nsuserdefaults

iOS 10 with XCode 8 GM caused NSUserDefaults to intermittently not work

跟風遠走 提交于 2019-12-29 14:20:12
问题 NOTE: I have seen many other posts on Stack Overflow about NSUserDefaults being renamed to UserDefaults in Swift or not working on simulator until a restart. This is not a duplicate by anyway. Many of the questions SO is tagging against is from 4 years ago. My question is specific to iOS 10 from this year as this has always worked in older versions. I have mentioned in my question already that my question is not a duplicate of those questions as those were simulator bugs in swift and my issue

NSUserDefaults not working right

我们两清 提交于 2019-12-29 08:51:40
问题 Having some trouble with NSUserDefaults here. Here's how I'm creating it: NSString *theCity = @"Test City"; [[NSUserDefaults standardUserDefaults] setObject:theCity forKey:@"SavedCity"]; Here's how I'm trying to retrieve it: if ([[NSUserDefaults standardUserDefaults] objectForKey:@"SavedCity"]) { NSLog(@"Key exists! %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"SavedCity"]); } else { NSLog(@"No city saved!"); } The problem I have is that even if there IS a key for "SavedCity" (I

How to save json data on userdefaults in swift 4

走远了吗. 提交于 2019-12-29 08:02:18
问题 This is my model class class UserRoot : Mappable { var success : Bool! var user : UserDetails! var error = "" required init?(map: Map) { } func mapping(map: Map) { success <- map["success"] user <- map["user"] error <- map["error"] } } after successfully login i want to save this data on user defaults so that when a user have to not give login credential again. Here is my code class Default : NSObject{ static func saveToSharedPrefs(user: UserDetails!) { let d = UserDefaults.standard if user !

iPhone: Where NSUserDefaults get stored?

故事扮演 提交于 2019-12-29 07:27:28
问题 I am able to store, retrieve, and remove values using NSUserDefaults. I couldn't succeed to find out where NSUserDefaults getting stored physically on iPhone? I guess it should be plist file but not sure. Does anyone know if its possible to see this values on iPhone physically? Thanks. 回答1: Connect Your device to Xcode. Select Windows -> Organiser . Select your device. Click on your application. Click the gear icon and Download Container… . Select the downloaded .xcappdata file, right click

How to save NSMutablearray in NSUserDefaults

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-27 16:40:32
问题 I have two NSMutableArray 's. They consist of images or text. The arrays are displayed via a UITableView . When I kill the app the data within the UITableView gets lost. How to save array in UITableView by using NSUserDefault ? 回答1: Note: NSUserDefaults will always return an immutable version of the object you pass in. To store the information: // Get the standardUserDefaults object, store your UITableView data array against a key, synchronize the defaults NSUserDefaults *userDefaults =

How to save local data in a Swift app?

感情迁移 提交于 2019-12-27 12:08:40
问题 I'm currently working on a iOS app developed in Swift and I need to store some user-created content on the device but I can't seem to find a simple and quick way to store/receive the users content on the device. Could someone explain how to store and access local storage? The idea is to store the data when the user executes an action and receive it when the app starts. 回答1: The simplest solution if you are just storing two strings is NSUserDefaults , in Swift 3 this class has been renamed to

How can I use UserDefaults in Swift?

半腔热情 提交于 2019-12-27 10:59:46
问题 How can I use UserDefaults to save/retrieve strings, booleans and other data in Swift? 回答1: ref: NSUserdefault objectTypes Swift 3 and above Store UserDefaults.standard.set(true, forKey: "Key") //Bool UserDefaults.standard.set(1, forKey: "Key") //Integer UserDefaults.standard.set("TEST", forKey: "Key") //setObject Retrieve UserDefaults.standard.bool(forKey: "Key") UserDefaults.standard.integer(forKey: "Key") UserDefaults.standard.string(forKey: "Key") Remove UserDefaults.standard.removeObject

Save custom objects into NSUserDefaults [duplicate]

徘徊边缘 提交于 2019-12-27 10:31:31
问题 This question already has answers here : Saving custom Swift class with NSCoding to UserDefaults (12 answers) Closed 4 years ago . I'm having a news ViewController and a TeamViewController . The TeamViewController contain a tableView of teamObjects which when selected is added into array. I want to add this array into NSUserDefaults so i can access them from the NewsController which contain a url request where the teamObjects is needed. However i keep getting: 'Attempt to insert non-property

How to reinstall an app without losing NSUserDefaults?

旧城冷巷雨未停 提交于 2019-12-25 17:06:25
问题 I have an iOS game that saves game progress using NSUserDefaults. After the last update a user had a problem, the app was not working anymore on this device. The app doesn't have any problem, but for some reason an error occurred while downloading the app, not quite sure what happened. The point is, the app must be deleted and reinstalled. Can this be done without erasing NSUserDefaults? I tried syncing with iTunes here after deleting the app, even installing it again through iTunes but I was

Unable to retrieve NSMutableArray from NSUserDefaults

笑着哭i 提交于 2019-12-25 14:48:11
问题 I have an issue persisting data in local storage for an NSMutableArray containing a list of NSStrings. I have a save method and a get method both appear to work when the app is running. However, once I close the app and restart the items in the array are gone. NSMutableArray*ImageTags; Get Data -(NSMutableArray*)GetDataNSMutableArray:(NSString*)ItemName { NSMutableArray *GetData = [[NSMutableArray alloc] init]; NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults]; NSData