nsuserdefaults

Swift: Error in NSKeyedArchiver

穿精又带淫゛_ 提交于 2019-12-11 05:48:01
问题 Swift 3 iOS 10, Trying to save array with custom objects in NSKeyedArchiver, basically trying to save the table view after the user uses the buttons to switch between sections. I've tried several post to solve the issue but no luck, now I'm trying to do it myself NSCoding and NSKeyedArchiver. Error: Cannot convert value of type '[Blog]' to expected argument type 'NSCoder' Error is in code in Blog.swift, Code that handles NSCoding and my Blog Objects import UIKit class BlogsCoding: NSObject,

NSUserDefaults and saving size

谁说胖子不能爱 提交于 2019-12-11 05:42:29
问题 I have an app that tracks a user as they drive along. It uses CLLocationManager and each time the didUpdateToLocation is called I save the CLLocation point. A trip of around 25 miles yields somewhere in the neighborhood of 1200 points. As of now I save this array of points to the user defaults for testing. Should I look at CoreData to properly save this information? Or possible just write everything out to a file? My concern is that can NSUserDefaults "max out"? I could potentially have

UserDefaults between iOS and WatchOS not working

天涯浪子 提交于 2019-12-11 04:47:49
问题 Here is the code, but for some reason I get nil when I read from Watch. Any idea what am I missing? Writing in iOS Method @IBAction func writeDefaults(_ sender: Any) { UserDefaults(suiteName: "group.testingGroups")!.set(true, forKey: "myKey") } Reading from WatchOS @IBAction func readDefaults() { let readKey = UserDefaults(suiteName: "group.testingGroups")!.bool(forKey: "myKey") print("Key Value: \(readKey)") } I also tried the following when reading but nothing... let readKey = UserDefaults

use NSUserDefaults with array of struct type

南笙酒味 提交于 2019-12-11 04:30:00
问题 I have problems to figure out how to save my string of type "RiskEntry" with NSUserDefaults. I already went through some other posts, but somehow I still did not manage to solve this particular issue. Let me explain what the code from below does right now: I get some data from my class CustomCell in the following code snippet. Here I first check with an "identifier" which array to update with the new array value "consequences". It all works fine and the updated array is stored in riskEntry.

Are NSUserDefaults data synced to iTunes?

大憨熊 提交于 2019-12-11 04:28:32
问题 I understand that NSUserDefaults data is unencrypted and should not be used to store sensitive information. I'm trying to understand how easily someone could get at that information. This thread shows that it's just a plain file on the iphone filesystem. Will this file be transferred to the user's computer during an iPhone sync (if app sync is enabled)? If so, then it'd be extremely easy for anyone to read information stored in NSUserDefaults 回答1: Yes the file will be synced during a backup

NSUserDefaults - Saving UIImageView Position

不打扰是莪最后的温柔 提交于 2019-12-11 04:18:34
问题 In my application, I have a UIImageView and a UIButton. The UIImageView has a UIPanGestureRecognizer, and can be dragged around the screen. I have written: int defaultBallLocation = ball.center; in my - (IBAction)saveButton and Xcode is saying "Cannot associate CGPoint with int". So, how can I save the ball (UIImageView) position on the screen by pressing "save", then load the saved position by pressing "load" through NSUserDefaults? I have worked with NSUserDefaults before, but only with a

iOS/Swift 1.2 NSDictionray/Dictionary on NSStandardUserDefaults

随声附和 提交于 2019-12-11 04:04:49
问题 In the 'old' Swift, I used to register my defaults loaded from a .plist file like this... let prefs = NSBundle.mainBundle().pathForResource("UserDefaults", ofType: "plist"); let dict = NSDictionary(contentsOfFile: prefs!); let defaults:NSDictionary! = dict?.valueForKey("defaults") as! NSDictionary; NSUserDefaults.standardUserDefaults().registerDefaults(defaults); NSUserDefaults.standardUserDefaults().synchronize(); Under Swift 1.2, I get the error... Cannot invoke 'registerDefaults' with an

NSUserDefaults saves details sometimes and doesn't someother times

不羁的心 提交于 2019-12-11 03:43:54
问题 I use NSUserDefaults to save some data locally. But the problem is it doesn't save the data all the times. For instance: While an app is crashing I save the execption related informations using NSUserDefaults - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSSetUncaughtExceptionHandler(&onUncaughtException); } void onUncaughtException(NSException* exception) { //save exception related details using NSuserdefaults } 回答1: The

Can a nested enum be saved inside UserDefaults?

强颜欢笑 提交于 2019-12-11 02:22:29
问题 Let's say I have the following enums: enum UserState { case LoggedIn(LoggedInState) case LoggedOut(LoggedOutState) } enum LoggedInState { case Playing case Paused case Stopped } enum LoggedOutState { case Unregistered case Registered } Is there a way to save UserState to UserDefaults ? 回答1: Yes You can use Codable protocol to transform your enum into a representation that can be saved in UserDefaults. This tutorial might give you a kickstart. 来源: https://stackoverflow.com/questions/48348665

The proper way to delete rows from UITableView and update array from NSUserDefaults in Swift / iOS

ⅰ亾dé卋堺 提交于 2019-12-11 02:12:35
问题 What is the proper way to delete rows from UITableView and update array from NSUserDefaults? In the following example I'm reading an array from NSUserDefaults and feeding a UITableView with its content, I'm also allowing the user to delete items in the UITableView what I'm not sure is when to read and write to NSUserDefaults so the table updates as soon as a row is deleted. As you can see I start by reading the array the in the viewDidLoad method and re-saving it in the commitEditingStyle