How to offer custom code for Cocoa to invoke or communicate with
- Subclass and then override specific methods with custom behaviour
- Apply protocol and implement corresponding methods or functionality
- Via Notification mechanism, registering for interested notification, unregistering before gone.
- Using Timer
- Using delegation
- As data source
- Using Target-Action or Nil-Target-Action
- Via KVC and KVO. KVO is a notification mechanism that doesn’t use the NSNotification Centre. It allows one object to be registered directly with a second object so as to be notified when a value in the second object change.
- KVC, KVO, Introspection or some dynamic features (respondForSelector or so) are implemented in Objective-C runtime that access via NSObject method or Objective-C runtime programming.
- All custom class is an object whose type is Class that is a subclass of NSObject.
- An object has an isa pointer which points to its class object. And inside the object, there are a block of memory storing its properties and the isa pointer. When that object invokes a instance method, the runtime will use its isa pointer to find out which class object is that object’s class then call the method with that object’s address (object pointer) and resting parameters. And the class object has a property called super pointing to its superclass object and has an isa pointer pointing to Class object as well which is the class of class. That’s sort of implementation detail of Objective-C runtime.