Understanding issues with Class Methods?

Discussion in 'Mac Programming' started by q64ceo, Jul 6, 2013.

  1. macrumors regular

    Aug 13, 2010
    I am a little bit stuck on Class methods. I am completely new to Objective-C.

    Can anyone provide me an example?

    Here my best guess:

    Its kinda like Nouns and Verbs

    For example:

    [cat feeding]; // feed the cats

    Thank you for your time.
  2. macrumors 604


    Nov 26, 2007
    What you're describing sounds more like an instance method than a class method.

    Class methods do one of two things:
    1 - Generate a new instance (IE: alloc, stringWithFormat:, ...)
    2 - Serve as a stateless utility method that would probably be better off as a plain old C function.

    Instance methods are stately. Mostly you want to get and or set things based on the state of an instance of an object.

    Is that clear or is it too abstract?

    I feel like OOP is fairly complex and that it's mostly just you have to hear people talk about it and try working with it and its predecessors before you really get it and understand its benefits.
  3. thread starter macrumors regular

    Aug 13, 2010
    I will eventually get it.

    Maybe I should spend my time with Xojo. I have always been a BASIC kind of person. And, although its not Objective-C, it is an OOP programming environment based upon BASIC.
  4. macrumors member

    Apr 11, 2011
    It sounds like you're just describing methods at this point; not specifically class methods.

    In the message [cat feeding], the message "feeding" is sent to an instance of an object "cat." That means the "cat" object that received the message would execute its "feeding" method.

    One real benefit of Objective-C objects, though, is that they have methods that can seem intuitively similar to the things they represent. [cat meow] and [cat scratch: (other object) pieceOfFurniture] might be more appropriate methods to implement.

    A "class" is a basic definition of a kind of object -- something that could be used to create discrete instances of "cat," for example -- and its instances run methods. Classes can have their own methods too, but -- as someone was saying -- their uses are more generic and limited. If you're not sure, there's no need to use them.

    I think the two best resources for this are Apple's document "Programming with Objective-C" and, maybe even better, Stanford's introductory iOS App Development course on iTunes U.

Share This Page