I’ve been running into this problem a lot lately. I have an NSMutableArray called tests which is populated with instances of my custom class Test. I’m trying to access a property with the following method:
return [tests objectAtIndex:row].name;
However LLVM always throws an error and refuses to compile:
error: Semantic Issue: No member named 'name' in 'struct objc_object'
How do I tell the compiler that I’ll be accessing a Test object and to let me compile the damned thing?
Since
objectAtIndex:returnsid, that is, a generic pointer, the compiler can’t possibly know what method name to substitute for your property access.name.You have to completely specify to the compiler what you want to do in this case. Either specify the exact method name:
or specify the actual type of the object:
When you write
foo.bar, the compiler has to look infoo‘s class and find the method names associated with the propertybar. Those are usuallybar/setBar:, but they could be anything;* because of that ambiguity, the compiler needs to know the actual class offoo. Given only a generic pointer, it can’t find that information.The warning indicates that the compiler also checked whether the object on the left side of the
.is a struct with a field calledname. There isn’t such a field, so the compiler does not know what you want it to do.*E.g.,
@property(retain, setter=putThisValueIntoBar, getter=hamAndEggs) Bar * bar;