Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add rest of obj-c prog runtime guide notes.

  • Loading branch information...
commit 58e861f5d1d398b20962bcad5322b99cabdf70ab 1 parent 7f67a15
@mudphone authored
Showing with 48 additions and 0 deletions.
  1. +48 −0 README
View
48 README
@@ -170,7 +170,30 @@ The Objective-C Runtime Programming Guide
- self = receiver
- _cmd = selector
- You can use methodForSelector: to bypass dynamic binding... but, it's kind of cheating since this method is provided by Cocoa.
+
+- Dynamic Method Resolution
+ - @dynamic propertyName;
+ - Core Data NSManagedObject does this.
+ - You can implement resolvedInstanceMethod: and resolveClassMethod:
+- Dynamic Loading
+ - System Preferences modules
+ - NSBundle
+
+- Message Forwarding
+ - forwardInvocation: (it's kind of like Ruby's method_missing)
+ - (void)forwardInvocation:(NSInvocation *)anInvocation
+ {
+ if ([someOtherObject respondsToSelector:
+ [anInvocation selector]])
+ [anInvocation invokeWithTarget:someOtherObject];
+ else
+ [super forwardInvocation:anInvocation];
+ }
+ - Forwarding mimics multiple inheritance
+ - provides features of multiple inheritance
+ - but, multiple inheritance combines capabilities in single object
+ - forwarding provides abilities in smaller objects, associated in transparent way to the message sender
Method Swizzling
- Swizzling: transparently replacing one thing with another at runtime
@@ -185,6 +208,31 @@ Method Swizzling
- Use funtion pointer approach in RNSwizzle instead
- If still interested, read this:
http://robnapier.net/blog/hijacking-methodexchangeimplementations-502
+ - NSNotificationCenter Category Example:
+ @interface NSNotificationCenter (RNHijack)
+ + (void)hijack;
+ @end
+
+ @implementation NSNotificationCenter (RNHijack)
+ + (void)hijackSelector:(SEL)originalSelector withSelector:(SEL)newSelector
+ {
+ Class class = [NSNotificationCenter class];
+ Method originalMethod = class_getInstanceMethod(class, originalSelector);
+ Method categoryMethod = class_getInstanceMethod(class, newSelector);
+ method_exchangeImplementations(originalMethod, categoryMethod);
+ }
+
+ + (void)hijack
+ {
+ [self hijackSelector:@selector(removeObserver:)
+ withSelector:@selector(RNHijack_removeObserver:)];
+ }
+
+ - (void)RNHijack_removeObserver:(id)notificationObserver
+ {
+ NSLog(@"Removing observer: %@", notificationObserver);
+ [self RNHijack_removeObserver:notificationObserver];
+ }
ISA Swizzling
- ISA pointer defines the object's class
Please sign in to comment.
Something went wrong with that request. Please try again.