I was wondering if anyone would be kind enough to define what a class, instance and method is in Objective-C or point me in the right direction or a good Objective-C lear开发者_C百科ning resource.
Thanks!
For understanding the basic concepts, read the Wikipedia article on OOP.
Once you've understood that, the next step is to read up on Objective-C. For example, there's a nice document from Apple which you should read, and then there's the Objective-C Beginner's Guide. Apart from that, just search on Amazon and pick a book that has good rating/comments and that also covers topics you're interested in, like developing for the iPhone. Most iPhone development books start by giving a (short) introduction to Objective-C.
Once you have gotten your hands dirty with writing some Objective-C code, I recommend reading Cocoa Design Patterns. Do not read it as your first book, but do read it some day ! It explains why the Apple APIs (Cocoa) are the way they are, it explains the concepts and patterns you see in Cocoa. It's not a step-by-step guide but gives an understanding on how things work together.
As a start I'd use apple's Objective-c Primer: http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/
I'd also adise you to look for tutorials about "Object Oriented Programing", to learn its basic concepts.
But to answer your question:
A class is like an Object type. You write the definition of your classes in your source code. In objective-c this happens in the @interface and @implementation parts. An example for a class would be "cars".
A class has class variables: usually of a simple type, like int or bool, or a pointer to another class. A class also can have methods, which are like methods, or functions in sequential programming (c, or similar). A class method for "car" could be "change tires", an class variable could be "license plate".
These are merely definitions of how your class looks like and how it behaves. Like the fact, that integer is a number. which number any int in your program is, would be the instacne. Or to use the "car"-example: "car" is the class and the silver-coloured, mercedes with the licence plate number 'xy-123' is an instance of the class.
Have fun coding!
Class = Car
Instance = Tire
Method = turnLeft
@interface Car: NSObject {
id tire;
}
@property id tire;
- (void)turnLeft;
@end
精彩评论