I’d like to be able to write
id foo = [MyObject new];
foo.bar = [NSObject new];
But I get the following error:
/blah/blah/blah/Blah.m:32:9: error: property 'bar' not found on object of type '__strong id'
foo.bar = [NSObject new];
^
1 error generated.
Since clang doesn’t report a warning I could suppress, I assume this behavior is permanent, but I hope someone can tell me otherwise.
Obviously, I know this will break by default, but I plan to use Dynamic Method Resolution to make it work.
You can’t use the dot syntax on a generic object pointer like this.
The reason is that the compiler rewrites
foo.bar = baz;to[foo setBar:baz], but since you can change the setter’s name,@property (strong, nonatomic, setter=setListOfApples:) NSArray * listOfOranges;, it must be able to see the property declaration.If you use the standard message send syntax, this will work. In other words, you have to either tell the compiler the exact type of the object so that it can look up the property’s setter, or tell it the exact setter name you want it to use.