Intercept Objective-C delegate messages within a subclass

To avoid overriding all of the delegate methods manually, you can use message forwarding. I just implemented the same thing using an intermediate proxy class as follows: MessageInterceptor.h @interface MessageInterceptor : NSObject { id receiver; id middleMan; } @property (nonatomic, assign) id receiver; @property (nonatomic, assign) id middleMan; @end MessageInterceptor.m @implementation MessageInterceptor @synthesize receiver; @synthesize … Read more

How can I add properties to an object at runtime?

It’s possible to add formal properties to a class via class_addProperty(): BOOL class_addProperty(Class cls, const char *name, const objc_property_attribute_t *attributes, unsigned int attributeCount) The first two parameters are self-explanatory. The third parameter is an array of property attributes, and each property attribute is a name-value pair which follow Objective-C type encodings for declared properties. Note … Read more

Get all methods of an Objective-C class or instance

In addition to Buzzy’s answer, for debugging purposes you may use the -[NSObject _methodDescription] private method. Either in lldb: (lldb) po [[UIApplication sharedApplication] _methodDescription] or in code: @interface NSObject (Private) – (NSString*)_methodDescription; @end // Somewhere in the code: NSLog(@”%@”, [objectToInspect performSelector:@selector(_methodDescription)]); Output will look as following: <__NSArrayM: 0x7f9 ddc4359a0>: in __NSArrayM: Class Methods: + (BOOL) … Read more

Class is implemented in both. One of the two will be used

I wrote that error message!• Either change the class name or don’t link against said library. How is your project configured? Is there anywhere where you explicitly link against SR? Or is it a product of linking against two static libraries that both already include SR? If the former, then stop linking against SR directly … Read more

What exactly is super in Objective-C?

super Essentially, it allows you to use the implementations of the current class’ superclass. For the gritty details of the Objective-C runtime: [super message] has the following meaning: When it encounters a method call, the compiler generates a call to one of the functions objc_msgSend, objc_msgSend_stret, objc_msgSendSuper, or objc_msgSendSuper_stret. Messages sent to an object’s superclass … Read more

How to implement an IMP function that returns a large struct type determined at run-time?

It seems that the Apple engineer is right: the only to way to go is assembly code. Here are some usefull pointers to getting started: From the Objective-C runtime code: The i386 and x86_64 hand-crafted messenger assmbly stubs for the various messaging methods. An SO answer that provides an overview of the dispatching. A in-depth … Read more

What is objc_setAssociatedObject() and in what cases should it be used?

objc_setAssociatedObject adds a key value store to each Objective-C object. It lets you store additional state for the object, not reflected in its instance variables. It’s really convenient when you want to store things belonging to an object outside of the main implementation. One of the main use cases is in categories where you cannot … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)