Objective-C Explained; - / + and * var

I teach myself Objective-C from a book (Cocoa for Mac OS X), and I'm halfway there, but I have two questions that are not answered or not defined in the book.

  • When defining class methods, what is the difference between (assumed in the .h file):

    - (int),

    + (int),

The way I see it at the moment is that the methods -require the class to be assigned and initialized first, however +it can be called statically without requiring allocation and initialization. For example. (in function in another class)

// Using -
Earth *world = [[Earth alloc] init];
int population = [world population];

// Using +
int population = [Earth population];

If this is correct, when should static methods be used, and do they have any disadvantages?

  1. var paramater var *, , var ? ( .)

    - (void) setPopulation: (NSNumber *) ;// *, NSNumber

    - (void) setPopulation: (int) ;// , *

, - Objective-C, .. PHP Ruby.

+5
3

-/+ Objective-C , . , Objective-C , . :

@interface MyObject : NSObject
-(void)myInstanceMethod;
+(void)myClassMethod;
@end

// ...

MyObject* obj = [[MyObject alloc] init];

[obj myInstanceMethod];      // this is okay
[obj myClassMethod];         // this will fail
[[obj class] myClassMethod]; // this is okay
[MyObject myClassMethod];    // this is okay
[MyObject myInstanceMethod]; // this will fail

, Objective-C - C. , C, Objective-C. - . C * , . C, Objective-C .

/ . googling C , .

+21

, ?

0

+ - , . / factory . - , . (-). OO! , .

0

All Articles