Obj-C / Cocoa

Discussion in 'Public Game Developers Forum' started by jwei44, Apr 20, 2011.

  1. jwei44

    jwei44 Well-Known Member

    Dec 4, 2009
    448
    0
    0
    High School Graduating
    California
    I recently purchased a book and it went good until I reached the memory management section of the book.

    If anyone could possibly (minimally) explain + or - class/class methods.

    Code:
    - (float)circumferenceFromRadius:(float)radius;
    Or even something like that...

    Well, if you can help, let me know and I'll ask some questions.
     
  2. ArtCoder

    ArtCoder Well-Known Member

    If they start with + they are class methods. You call them like this:
    Code:
    [ClassName methodName];
    If they start with - they are instance methods. You need an object of that class:
    Code:
    ClassName* instance = [ClassName new];
    [instance methodName];
    I hope that helps.
     
  3. kohjingyu

    kohjingyu Well-Known Member

    Mar 20, 2009
    1,770
    0
    0
    Student/Developer
    Singapore
    For instance methods it can also be called like

    Code:
    ClassName *className = [[ClassName alloc] init];
    [className callMethod];
    [className release];
    
    That's personally what I use - it's just more natural for me ;)
     
  4. jogo

    jogo Well-Known Member

    Mar 17, 2011
    137
    0
    0
    And the way for iOS.
    But for a release direct after a call/or more autorelease is easier to type.
     

Share This Page