On Github siejkowski / NSTouki
typedef struct objc_class *Class; typedef struct objc_object *id; struct objc_object { uintptr_t isa; /* ivars */ } struct objc_class : objc_object { Class superclass; /* cache, ivars description list, methods list */ }to przybliżenie, bo obecnie runtime jest znacznie bardziej zoptymalizowany jeśli czas, to anegdotka o isa w 64 bitach objective c runtime 2.0 skrył wiele, ale koncepcja pozostała podobna cache, ivars list, method list - to wszystko struktury - wejść do runtime.h
[obj message];
objc_msgSend(obj, @selector(message));︎
- (NSString*)string:(NSString* string) { /* ... */ }
NSString* string(id self, SEL _cmd, NSString* string) { /* ... */ }︎
[object performSelector:@selector(selector)];
-(SEL)soMuchHigherOrderEatThisJava:(SEL) { /* ... */ }
[classes valueForKeyPath:@"method.chain.lol"];
method_exchangeImplementations(original, new);
objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes)
id objc_setAssociatedObject(id object, void *key);
class_addMethod(Class cls, SEL name, IMP imp, const char *types)AssociatedObject jest fajny w połączeniu z kategoriami
[object isMemberOfClass:[SomeClass class]];
[object isKindOfClass:[SomeClass class]];
[object conformsToProtocol:@protocol(SomeProtocol)];
[object respondsToSelector:@selector(SomeMethod)];
Method * class_copyMethodList(Class c, unsigned int *count)introspekcja jest bardzo często używana tyle o runtime
id object = [Class alloc];
Class object = [object init];
Class object = [Class new]; (+ helpers like [NSArray array])
Class second = [object copy];
[object dealloc];
[object retain];
[object release];
[object autorelease];
// ARC was herereference counting jest super przez moment nawet garbage collector był, ale nie wszedł na długo
self.myLovelyBlock = ^{ [self whatever]; // OMG it's a cycle! }
__weak typeof(self) bself = self; self.myLovelyBlock = ^{ [bself whatever]; // OMG it's weak! }
[nil method] == nil // YES!
@property(strong, assign, atomic, readwrite)
@property(weak, unsafe_unretained, copy, assign, nonatomic, readonly)
NSArray* / NSMutableArray*
NSDictionary* / NSMutableDictionary*
NSSet* / NSMutableSet*
dispatch_sync / dispatch_async
dispatch_once
dispatch_after / dispatch_time
dispatch_queue_create / dispatch_get_main_queue
#define
@interface
@implementation
@interface ( ... )
@protocol
@property
@dynamic
@selector
NSArray* / NSMutableArray*
NSDictionary* / NSMutableDictionary*
NSSet* / NSMutableSet*
NSString* / NSMutableString*
NSNumber *
@"", @1, @[], @{}, @(1 + 2)