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

How to copy an object in Objective-C

As always with reference types, there are two notions of “copy”. I’m sure you know them, but for completeness. A bitwise copy. In this, we just copy the memory bit for bit – this is what NSCopyObject does. Nearly always, it’s not what you want. Objects have internal state, other objects, etc, and often make … Read more

ViewController respondsToSelector: message sent to deallocated instance (CRASH)

Use Instruments to track down deallocated instance errors. Profile your application (Cmd ⌘+I) and choose Zombies template. After your application is running, try to crash it. You should get something like that: Click on the arrow next to address in the popover to show object that was called after it was deallocated. You should see … Read more