I donβt know if this is possible with properties, but if it is, I donβt think you are using the correct syntax.
You tried to change
id boo = [obj valueForKey:@"foo"];
to read
Foo boo = obj.foo;
?
Foo is not and never will be id . valueForKey: returns id, and the runtime may be blocked by trying to compress struct Foo in NSValue .
If for some reason you need to use valueForKey: your calls should look like.
Foo myFoo = FooFactory(); Object *myObj = [Object new]; [myObj setValue:@( myFoo ) forKey:@"foo"]; Foo myFooOut; [[myObj valueForKey:@"foo"] getValue:&myFooOut];
In this case, if the NSValue mechanism really cannot handle the packed structure, you just need to write the accessors in the old-fashioned way: -<key> and -set: `.
PS: Never call the class "Object", in fact there is an Object in some SDKs that NSObject inherits. I guess only in your example.
source share