Note that there are some explanatory texts on larger screens.

plurals
  1. PONSNumber out of scope?
    primarykey
    data
    text
    <p>I've written an Objective-C class and I'm using a shared instance of it across several of the views in my iPhone project. Its member variables include bools, ints, NSStrings and one NSNumber. The shared instance seems to work just fine across the scope of my application, except for the NSNumber which the debugger tells me is "out of scope" once the shared instance has been accessed for the 2nd or subsequent times.</p> <p>Here's a quick overview of what I'm doing...</p> <pre><code>// UserData.h @interface UserData : NSObject { TaxYears selectedTaxYear; NSNumber *grossWage; // &lt;--- this is the troublesome member // ... NSString *other; int age; } + (UserData *)getSharedUserData; @end // UserData.m #import "UserData.h" @implementation UserData static UserData *sharedUserData = nil; // Points to the shared object + (UserData *)getSharedUserData { if(sharedUserData == nil) { sharedUserData = [[UserData alloc] initWithTaxYear:0]; [[NSNotificationCenter defaultCenter] addObserver:sharedUserData selector:@selector(doTerminate:) name:UIApplicationWillTerminateNotification object:nil]; } return sharedUserData; } - (id)initWithTaxYear:(TaxYears)theTaxYear { if ((self = [super init])) { } return self; } - (void)updateGrossWage:(NSNumber *)theGrossWage { grossWage = theGrossWage; } - (NSNumber *)getGrossWage { return grossWage; } // ... @end </code></pre> <p>So it is accessed in one view like this:</p> <pre><code>UserData *userData userData = [[UserData getSharedUserData] retain]; </code></pre> <p>And in another view in the same way. But the second time it is accessed, the grossWage member is out of scope, but everything else is fine - this is why I'm stumped. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload