Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AlbuquerqueApac

macrumors member
Original poster
Jan 13, 2012
47
0
Ok, so I have a class that I want to add an NSnumberFormatter to, The problem is I want to be able to access the object from anywhere within my class. Unfortunately, I don't see how to allocate it on the heap without constantly overwriting constantly. I overwrite my init method, but Xcode still doesn't like me trying to access it.
 
Go back to your fundamentals, especially those concerning scope. It sounds like you want a variable that can be accessed throughout an instance of your class. Does that hint give you any ideas?

I overwrite my init method, but Xcode still doesn't like me trying to access it.

"Doesn't like" you? That's far too vague. Be specific. If Xcode give you warnings or errors, provide those. When they are related to specific sections of code, provide that code. Respect those you seek help from; we are not mind readers!
 
Ok, Xcode still does not see the NSformatter Object I allocated. When I go to send a message to it

[formatter (here)] Xcode behaves as if this variable "formatter" is undeclared.

Here is my init overwrite:

Code:
-(id) init
{
    if (self = [ super init]) 
    {
        NSNumberFormatter  *formatter = [[NSNumberFormatter alloc] init];
        [formatter setAlwaysShowsDecimalSeparator:YES];
        [formatter setGeneratesDecimalNumbers:YES];
        [formatter setDecimalSeparator: @"."];
         
        
        
        
    }
         
         return self;
         
}


These are both in my implementation file.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.