I am trying to introduce some generics-style approaches from .NET into my iOS development. I am retrieving a list of custom objects of type Example.
I have defined a protocol that Example class implements:
@protocol ExampleProtocol
@property(nonatomic,assign) int Id;
@property(nonatomic,copy)NSString *Description;
@optional
@property(nonatomic,copy)NSString *Icon;
@end
I then retrieve my NSMutableArray of Example as follows:
id<ExampleProtocol> anExample = [arrayOfExampleProtocols objectAtIndex:0];
The problem I have is that anExample
is always empty regardless of the contents of the NSMutableArray. My ultimate aim is to be able to reference the properties with the following syntax:
id<ExampleProtocol> anExample = [arrayOfExampleProtocols objectAtIndex:0];
NSString *test = [anExample Description];