is it possible to specify that a NSMutableArray can only contain a certain type of objects.
For example, if I want to store only this kind of objects :
@interface MyObject : NSObject {
UInt8 value;
}
In order to be able to use the instance variable like this :
- (void)myMethod:(NSMutableArray *)myArray{
for (id myObject in myArray){
[self otherMethod:myObject.value];
}
}
because I’m getting this error :
request for member 'value' in something not a structure or union
Thank you for your help
You are getting that error, because for as far as Objective-C is concerned,
myObjectis of the non-typeid, which doesn’t support thevalueproperty. To make Objective-C aware of the fact it’s always dealing with aMyObjectin this loop, you’ll have to tell it themyObjectobject is an instance ofMyObject.Also, you have to make sure the
valueivar is accessible using dot-notation by implementing getter and setter methods for it. You can do this yourself by implementing-valueand-setValue:, or you can use@propertyand@synthesizeto let Objective-C do this.