Question about Methods

Discussion in 'iOS Programming' started by Will0827, May 6, 2012.

  1. Will0827 macrumors regular

    Will0827

    Joined:
    Aug 11, 2008
    #1
    Im going over the source code for something i want to implement into my project and noticed some lines in the .m files of the source code and there are some methods that look like this

    - (BOOL)isToday { return [self isEqual:today]; }
    - (unsigned int)day { return a.day; }

    in the h files these methods don't have any arguments but in the .m files they have these curly brace arguments. Im not sure as what there use is. Any one care to help, thanks.
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    The curly braces indicate the start and end of the method. Generally they'd be on seperate lines, but neither C nor Obj-C actually care about line breaks. Line breaks are mostly just used to make code easier to read.
     
  3. Will0827 thread starter macrumors regular

    Will0827

    Joined:
    Aug 11, 2008
    #3
    Darn now I feel kinda stupid. I guess because I'm so used to seeing the opening curly brace be placed on the following line after the method name I found it weird at first. Thanks for the reply.
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Every developer has their own ideas about where the braces go. Some are downright odd. These methods are obviously meant to take up as little space as possible. It's also reminiscent of the way some people write inline methods in the headers of C++ classes.
     
  5. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #5
    I wouldn't be alive to post this if my school computer teacher ever found me doing this :D
     

Share This Page