How to allocate NSnumberFormatter to my class

Discussion in 'iOS Programming' started by AlbuquerqueApac, May 22, 2012.

  1. AlbuquerqueApac macrumors member

    Joined:
    Jan 13, 2012
    #1
    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.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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?

    "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!
     
  3. AlbuquerqueApac thread starter macrumors member

    Joined:
    Jan 13, 2012
    #3
    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.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Answer this question: what is the scope of your formatter variable?
     

Share This Page