Skip to content

Instantly share code, notes, and snippets.

@hcrub
Created November 7, 2013 17:42
Show Gist options
  • Save hcrub/7358702 to your computer and use it in GitHub Desktop.
Save hcrub/7358702 to your computer and use it in GitHub Desktop.
Objective C Runtime's class_addIvar adding a new instance variable to a class
/**
* class_addIvar
* Adds a new instance variable to a class.
*
* BOOL class_addIvar(Class cls, const char *name, size_t size, uint8_t alignment, const char *types)
*
* Return Value
* YES if the instance variable was added successfully, otherwise NO.
**/
- (BOOL)addInstanceVariable
{
return class_addIvar(subClass, "varName", sizeof(id), rint(log2(sizeof(id))), @encode(id));;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment