nsuserdefaults

Save UIButton state and load with NSUserDefaults

我的梦境 提交于 2019-12-25 03:55:31
问题 I was wondering how to detect whether the button was hidden or not, and how much alpha was applied to it. Then, when viewDidLoad is called, these values can be applied to make the buttons the same state they were left in when the application closed. How can I code this? Thanks, James 回答1: If, as your title suggests, you want to use NSUserDefaults , then you can set them like this: -(void)saveButtonState:(UIButton*)button { NSUserDefaults defaults = [NSUserDefaults standardUserDefaults];

'String' is not identical to 'AnyObject' error

对着背影说爱祢 提交于 2019-12-25 03:07:43
问题 I'm having issues when trying to pass data to my Apple Watch app through NSUserDefaults from my app. Whenever I try to retrieve the array that is stored, I am getting the error 'String' is not identical to 'AnyObject' . I've been trying to figure out a solution but I can't work out what the issue is since I am using the same method elsewhere in my app and it works without issue. Here is what I have in the Apple Watch part: var defaults = NSUserDefaults(suiteName: "group.AffordIt") tempNames =

'String' is not identical to 'AnyObject' error

六眼飞鱼酱① 提交于 2019-12-25 03:07:05
问题 I'm having issues when trying to pass data to my Apple Watch app through NSUserDefaults from my app. Whenever I try to retrieve the array that is stored, I am getting the error 'String' is not identical to 'AnyObject' . I've been trying to figure out a solution but I can't work out what the issue is since I am using the same method elsewhere in my app and it works without issue. Here is what I have in the Apple Watch part: var defaults = NSUserDefaults(suiteName: "group.AffordIt") tempNames =

NSUserDefaults with time floats

99封情书 提交于 2019-12-25 02:58:14
问题 I'm making a game in which the user must complete a task as quickly as possible, and I would like to display the user's best time and update the best time when he or she achieves a new one. I have: float BestTimeValue float starttime -(void)start{ starttime += 0.001; timelabel.text = [NSString stringWithFormat:@"%.3f", starttime]; } if (starttime < BestTimeValue) { [[NSUserDefaults standardUserDefaults] setObject:starttime forKey:[@"BestTimeValue"]; } and in my viewdidload: BestTimeValue = [

Adding to a Previously saved NSUserDefaults

别说谁变了你拦得住时间么 提交于 2019-12-25 02:55:47
问题 I am making a game for iOS which in includes a scoring system in each level. Here I have some code that gets an NSString ( passedValue1 ) by using a delegate. Heres the code for the delegate: LevelCompleteLevel1 .h #import "ViewController.h" @interface LevelCompleteLevel1 : UIViewController{ IBOutlet UILabel *label; ViewController *secondviewData; } @property (nonatomic, retain)ViewController*secondviewData; .m ViewController *second = [[ViewController alloc] initWithNibName:nil bundle:nil];

NSUserDefaults in iOS 8 and under iOS 8

喜你入骨 提交于 2019-12-25 02:42:12
问题 I know NSUserDefaults saves data in a app, so data is cleared after deleting app under iOS 8. but data persists after deleting app in iOS 8. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; Below codes works in iOS 8 (data is cleared after deleting app) NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.AppCompany.Appname"]; Does this code works under iOS 8? 回答1: If you are running your application in ios Simulator NSUserDefaults will not be

Resolving conflicting struct value types in swift

孤街醉人 提交于 2019-12-25 01:49:00
问题 I have a UITableViewController. Each row is populated from a global array. This global array Describes the title of a task. Each task has some associated variables which are strings. I want to be able to click on the title of task in the table view controller and have the associated variables linked to that title. The global array will be grow and shrink as the end user appends or removes titles from the global array. This is made with a struct. The struct contains the specific variables. The

NSUserDefaultsController: “Attempt to set a non-property-list object … as an NSUserDefaults/CFPreferences value for key …”

◇◆丶佛笑我妖孽 提交于 2019-12-25 01:09:01
问题 I'm trying to use NSUserDefaultsController to implement a Preferences window in my Swift macOS app. One of the settings that I need to persist is an array of presets, as defined by the following class: class Preset: NSObject { var name = "abc" var value = 123 override init() { super.init() } } Therefore, I need to persist a variable of type [Presets] . The visual representation in my Preferences window is an NSTableView , bound to an NSArrayController . I followed this tutorial to set up my

NSUserDefaults intitial setup

巧了我就是萌 提交于 2019-12-24 19:23:47
问题 I'm saving a few user settings in NSUserDefaults . If these settings have not been modified by the user, I'd like the app to use presets. How should I set this up so the app first checks if settings have been modified and if not, sets presets? Checking if [[NSUserDefaults standardDefaults]objectForKey: @"setting1"] == nil ? Then setting a preset if it is not? 回答1: [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary]; https://developer.apple.com/library/mac/#documentation/Cocoa

Can NSUserdefaults save two arrays of same name

醉酒当歌 提交于 2019-12-24 18:19:49
问题 Can NSUserdefault save two arrays of same name or it replaces previous array? 回答1: yes it replace with same variable and xcode not allowed to duplicate the same name of any object in same class so your application not compile until you not remove any one array name from class... Update:- In AppDelegate.h file just declare variable... NSUserDefaults *userDefaults; NSMutableArray *yourArray; after... In AppDelegate.m Fille in applicationDidFinishLonching: Method userDefaults = [NSUserDefaults