What you want is not possible. The compiler will not let you send any message without that selector being declared before. This of course includes accessing properties. This is necessary so the compiler can know what types to expect - not everything is an object. The compiler must generate different code for objects (think of ARC), structs or scalars.
The runtime on the other hand would be happy to handle this without having declared those properties. But then your job would be to call the right variant of objc_msgSend
casted to the right signature. This of course requires code that is much uglier than just using valueForKey:
and setValue:forKey:
directly.
Also @dynamic
doesn't really have anything to do with that. All @dynamic
does is shut up the compiler about missing implementations for getters and setters and preventing it from automatically generating them. It's a way for promising the compiler that at runtime those messages are going to be handled. Using @dynamic doesn't automatically forward property access to valueForKey: and setValue:forKey:.