How do I use this function +(NSString*)GUIDString {

Discussion in 'iOS Programming' started by Jules2010, Apr 9, 2010.

  1. Jules2010 macrumors member

    Joined:
    Apr 7, 2010
    #1
    I just can't get the syntax right..

    Code:
    +(NSString*)GUIDString {
    Thanks in advance.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    1) It's not a function: it's a class method

    2) Pretty simple:

    Code:
    [NameOfClassThatThisIsDeclaredInButYouChoseNotToTellUs GUIDString];
    
    Replace NameOfClassThatThisIsDeclaredInButYouChoseNotToTellUs with whatever the name of the class (not an instance of the class) is. I would note this is very basic Objective-C. Perhaps some time spent with the documentation would be a good idea?
     
  3. Jules2010 thread starter macrumors member

    Joined:
    Apr 7, 2010
    #3
    Thanks, I'm using it in the same class so I was just using self.
    Now I've tried the name of the function, which worked.
    I thought self would have worked thanks.

    I have been looking at the documentation and some books I bought, the objective c book isn't quite the same though.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Using self would make it an instance method call, since self is an instance. Make sure you understand the difference between class methods and instance methods.
     
  5. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #5
    Depends on the context of calling self...if called from within another class method, self refers to the class, not an instance of that class (classes are like instances too).
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Oops. Yeah, you're right. Forgot about that.
     

Share This Page