NSNumber not saved?

I have a variable lastPostsGrabbedCounter , a NSNumber , which is defined below.

 .h NSNumber *lastPostsGrabbedCounter; @property (nonatomic, retain) NSNumber *lastPostsGrabbedCounter; .m @synthesize postDetailViewController, lastPostsGrabbedCounter; - (void)viewWillAppear:(BOOL)animated { self.lastKnownLocation = [[CLLocation alloc] init]; self.lastPostsGrabbedCounter = [[NSNumber alloc] initWithInt:25]; [self showActivityViewer]; } 

This .m file is the table controller in my main view. When the application loads, this viewWillAppear receives a call, but if I switch to another TAB and return, and I try to use var lastPostsGrabbedCounter , do I show it as nil?

Why is it not saved when I leave?

+4
source share
1 answer

If NSNumber has not been saved, your application (most likely) will crash, or at least will behave badly. What you see nil means that a very different problem arises.

Make sure you do not terminate it with any other code. Also, make sure that you return to the instance that you think. A handful of NSLog(@"%@ %p", [self class], self]); distribution NSLog(@"%@ %p", [self class], self]); by all methods can be very useful.

And as Andre said, you missed the number; excessive preservation of it.

+4
source

Source: https://habr.com/ru/post/1346455/


All Articles