Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 6, 2013, 04:15 PM   #1
q64ceo
macrumors regular
 
Join Date: Aug 2010
Understanding issues with Class Methods?

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.
__________________
iMac i7 27inch mid 2010 | iPod Touch 4th Generation | iPad 2 | eMac 1.25 PPC mid-2004 | So I sold out and got an iPhone. Using all this Apple stuff is making me rusty on my real computer skillz
q64ceo is offline   0 Reply With Quote
Old Jul 7, 2013, 12:45 AM   #2
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
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.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Jul 7, 2013, 07:39 AM   #3
q64ceo
Thread Starter
macrumors regular
 
Join Date: Aug 2010
Quote:
Originally Posted by ArtOfWarfare View Post
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.
__________________
iMac i7 27inch mid 2010 | iPod Touch 4th Generation | iPad 2 | eMac 1.25 PPC mid-2004 | So I sold out and got an iPhone. Using all this Apple stuff is making me rusty on my real computer skillz
q64ceo is offline   1 Reply With Quote
Old Jul 7, 2013, 05:28 PM   #4
Starfia
macrumors newbie
 
Join Date: Apr 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.
Starfia is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
The Java class file "PopSampleApplet.class" could not be launched. piratemacfan OS X 10.8 Mountain Lion 0 Aug 30, 2013 04:03 PM
Referencing a child class in a parent class, good or bad? SAIRUS iPhone/iPad Programming 11 Aug 28, 2013 12:59 PM
Class methods vs instance methods zijianz iPhone/iPad Programming 8 Jul 20, 2012 12:15 PM
Difference between Public class and private class. zijianz iPhone/iPad Programming 4 Jun 29, 2012 10:29 PM
Private class methods KarlJay iPhone/iPad Programming 9 Jun 12, 2012 08:29 AM

Forum Jump

All times are GMT -5. The time now is 02:22 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC