Is the id type in Objective-C really dynamic

Is the id type really dynamic (late binding at runtime) or similar to the 'var' keyword in C # (late binding at compile time)?

+3
source share
2 answers

From the Objective-C Programming Language :

id is defined as a pointer to the data structure of the object:

typedef struct objc_object {
    Class isa;
} *id;

and more importantly

id . , , . - , . id , .

isa - . () ( ) .

, . , , , , . ( , . Objective-C .) Objective-C , .

+9

. ( ). . , :

Class classes[3];
classes[0] = [NSMutableString class];
classes[1] = [NSMutableArray class];
classes[2] = [NSMutableData class];
srandom(time(NULL));
id foo = [[classes[random % 3] alloc] init];
NSLog(@"It is a %@", [foo class]);
+6

Source: https://habr.com/ru/post/1774203/


All Articles