nsuserdefaults

NSUserDefaults vs sqlite3

折月煮酒 提交于 2019-12-01 09:09:43
问题 I have a small iPhone app that stores a list of objects. The user can add and remove objects, but this list will remain fairly small (most users would have 10-30 objects). NSUserDefaults seems much easier to work with, but will sqlite3 be faster? With only 30 "records" will there be any noticeable difference? 回答1: NSUserDefaults is for user preferences, usually basic objects like NSString or NSNumber. Sqlite, serializing a collection of objects in a property list, or Core Data are all valid

how can store custom objects in NSUserDefaults

ε祈祈猫儿з 提交于 2019-12-01 08:56:01
I apologize for duplicate Question . I am new in ios . I want to store custom objects in userdefaults. I am using objective-c . Thanks in advance First you create custom class Like below. CustomObject.h #import <Foundation/Foundation.h> @interface CustomObject : NSObject<NSCoding> @property(strong,nonatomic)NSString *name; @end CustomObject.m #import "CustomObject.h" @implementation CustomObject - (void)encodeWithCoder:(NSCoder *)encoder { //Encode properties, other class variables, etc [encoder encodeObject:self.name forKey:@"name"]; } - (id)initWithCoder:(NSCoder *)decoder { if((self =

See NSUserDefaults file content

自作多情 提交于 2019-12-01 08:49:45
Is there any way I can see the content of NSUserDefaults? I'm able to open the plist file using "pico" from the terminal, but it shows weird characters, I can't actually see the content file content. Is there any way I can open the file in Xcode? Basically, I want to be able to see and edit the content of NSUserDefaults without the need of doing so programmatically, I'd like to do so from the Terminal or from Xcode. Cheers! I'm able to open the file using "pico" but it shows weird characters. Because as an optimization (storage space and read/write speed) iOS stores property list files in the

Error when trying to save to NSUserdefaults

与世无争的帅哥 提交于 2019-12-01 08:40:18
I have a table which works in the following way. If a row is selected, an amount corresponding to the selected row is added to var total , a checkmark is added. If it is deselected, the amount will be subtracted, the checkmark will be set to none. My code worked properly before trying to save/retrieve the data to/from NSUserDefaults. The errors are: when I select the first row, it subtracts the amount instead of adding it; after a row is selected, if I tap on the back button and then come back to same screen the checkmark is not displayed. In this construct when I try to retrieve from

force reset NSUserDefault on iPhone App upgrade

为君一笑 提交于 2019-12-01 08:18:43
i want to force reset to NSUserDefault whenever user update my app. why i need this because every update include some new information abt user. as some info (token) already present in NSUserDefault my app does not call to my web service. due to that fact i dont have new user info. and also i dont want to write if..else statement for every new release. thanks so much. hope my question is pretty clear. Check this out: [NSUserDefaults resetStandardUserDefaults] For more info check the NSUserDefaults Class reference . What you can do is save on the defaults the current version of your app. All the

How to set response data into TodayExtenstion widget

北慕城南 提交于 2019-12-01 07:31:40
问题 Trying to access response data from service to show into TodayExtenstion Widget import Foundation struct MarketIndex:Codable { let indicesName: String let indicesValue: String let dateValue : String let indicesChangeValue : String let changePercentage : String let indexVolume: String? } struct MarketIndexCache { static let key = "MARKET_INDEX_KEY" static func save(_ value: [MarketIndex]!) { UserDefaults.standard.set(try? PropertyListEncoder().encode(value), forKey: key) } static func get() ->

IPhone SDK Default NSUserDefaults

隐身守侯 提交于 2019-12-01 07:24:47
问题 I have set up the user defaults to record a integer for a UISlider, the problem is that, if the user has only just installed the app then the integer is zero or NULL. Is there a way to detect if it = NULL with a integer? heres my code i have so far: -(void)awakeFromNib { NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; senset = [prefs integerForKey:@"senset"]; senset = sensitivity.value; } - (IBAction) setSens { senset = sensitivity.value; } - (IBAction) goBackopt { {

Saving and retrieving a bool with UserDefaults

一世执手 提交于 2019-12-01 07:10:22
问题 I'm trying to save a bool value to UserDefaults from a UISwitch, and retrieve it in another view. However, I've tried following multiple tutorials and stack answers and none seem to work. This is how I'm saving it: class SettingsViewController: UITableViewController { @IBOutlet weak var soundSwitchOutlet: UISwitch! @IBAction func soundSwitch(_ sender: UISwitch) { UserDefaults.standard.set(soundSwitchOutlet.isOn, forKey: "sound") } and this is how I'm trying to retrieve it in another view: if

How do I use UserDefaults with SwiftUI?

谁说胖子不能爱 提交于 2019-12-01 06:40:59
struct ContentView: View { @State var settingsConfiguration: Settings struct Settings { var passwordLength: Double = 20 var moreSpecialCharacters: Bool = false var specialCharacters: Bool = false var lowercaseLetters: Bool = true var uppercaseLetters: Bool = true var numbers: Bool = true var space: Bool = false } var body: some View { VStack { HStack { Text("Password Length: \(Int(settingsConfiguration.passwordLength))") Spacer() Slider(value: $settingsConfiguration.passwordLength, from: 1, through: 512) } Toggle(isOn: $settingsConfiguration.moreSpecialCharacters) { Text("More Special

Separate Settings in Universal iOS App?

江枫思渺然 提交于 2019-12-01 05:58:42
I'm working on an universal iOS app, but a few user settings don't make as much sense on the iPad. Can I specify a separate Settings.bundle or Root.plist for use on the iPad? from 4.0 on you will be able to just rename the file for ipad to contain ~ipad in name and ~iphoone for the iphone ones, for now you can only rename the iphone one and have 3.2 on ipad load the regular named ones. 来源: https://stackoverflow.com/questions/3277034/separate-settings-in-universal-ios-app