Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

q64ceo

macrumors 6502a
Original poster
Aug 13, 2010
517
782
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.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
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.
 

q64ceo

macrumors 6502a
Original poster
Aug 13, 2010
517
782
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.

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.
 

Starfia

macrumors 6502a
Apr 11, 2011
944
658
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.