I saved data that was saved using NSUserDefaults. I had the impression that if nothing was already stored in the key (when you first started the application), it would be 0. This does not seem to be the case.
Here is what I have:
To save:
- (void)viewWillDisappear:(BOOL)animated { [[NSUserDefaults standardUserDefaults] setInteger:setbatteryHealthCalculated forKey:@"healthValue"]; [[NSUserDefaults standardUserDefaults] synchronize]; }
For loading:
- (void) viewWillAppear:(BOOL)animated { NSInteger setbatteryHealthCalculated = [[NSUserDefaults standardUserDefaults] integerForKey:@"healthValue"]; }
To check the save value:
- (IBAction)check{ NSInteger setbatteryHealthCalculated = [[NSUserDefaults standardUserDefaults] integerForKey:@"healthValue"]; if (setbatteryHealthCalculated = 0) { [self performSelector:@selector(displayAlert) withObject:nil]; } }
if (setbatteryHealthCalculated = 0) {
Umm. Must be
if (setbatteryHealthCalculated == 0)
Comparison operator ==instead =in C-like languages.
==
=
setbatteryHealthCalculated 0 , . 0 , if , .
setbatteryHealthCalculated
if
, .
BTW, setbatteryHealthCalculated ivar? , NSInteger . , ivar.
registerDefaults: , ( , ). , . NSUserDefaults 0 nil , .
registerDefaults:
Source: https://habr.com/ru/post/1739532/More articles:What port address of the router must respond over time in order to live in a crowded message? - pingBuild a GUI application using MonoDevelop on OS X - user-interfaceNeed help using DefaultModelBinder for a nested model - asp.net-mvc-2does the array loop malfunction? C ++ - c ++BigDecimal to_s does not match to_f - ruby-on-railsВ следующей реализации static_strlen, почему нужны & и скобки вокруг str? - c++Python web game + Django and client browser polling - pythonInherited properties are not bound during data binding - c #Making noise using Python - pythonHow can I make an ASP.NET MVC site as a unit that can be tested as an ASP.NET Web Forms site? - asp.netAll Articles