How to create generic id type properties?-Collection of common programming errors
I’m new to iOS and Objective-C and trying to create a class that has a generic property.
@interface HeaderInfo : NSObject { NSString *label; id value; }
@property (nonatomic, retain) NSString *label;
@property (nonatomic, retain) id value;
- (HeaderInfo *)initWithLabel:(NSString *)lbl value:(id)val;
@end
Then I’m trying to add this class to an array:
[generalSection.items addObject:[[HeaderInfo alloc] initWithLabel:@"Tacho seal security" value:@"Some String Value"]];
[generalSection.items addObject:[[HeaderInfo alloc] initWithLabel:@"Tacho seal security" value:YES]];
but compiler doesn’t like the 2nd addition and says:
Warning: passing argument 2 of 'initWithLabel:value:' makes pointer from integer without a cast
What I’m doing wrong? Any help is greatly appreciated.
And also how can check the value later on whether it’s a BOOL or NSString?
Thanks.