0

Possible Duplicate:
dynamic properties in objective c
How can I add properties to an object at runtime?

Is there a way to actually create properties in runtime dynamically in iOS?

I am experimenting something here, and just wanted to see if it be possible?

Thanks.

Community
  • 1
  • 1
topgun
  • 2,463
  • 8
  • 31
  • 46
  • You can use [class_addMethod](http://developer.apple.com/library/ios/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/c/func/class_addMethod) to add the getters and setters. – Hot Licks Nov 03 '11 at 01:20

2 Answers2

1

you can generate types dynamically using ivars and methods, but there is not a means to get all the functionality of a declared property via one or two runtime calls.

a handful of functions should be all that is needed to accomplish the common routines, but a complete implementation would require some work and some syntactical noise.

justin
  • 104,054
  • 14
  • 179
  • 226
1

Properties are mapped to methods so you can add properties dynamically the same way you add methods dynamically using -[NSObject forwardInvocation:] and -[NSObject methodSignatureForSelector:] though you will have to use method syntax to call these methods and it can get complicated if you want to use primitive type properties.

Nathan Day
  • 5,981
  • 2
  • 24
  • 40