(id) issue, passing different types during initWith:(id)type
(id) issue, passing different types during initWith:(id)type
- Subject: (id) issue, passing different types during initWith:(id)type
- From: Travis Kirton <email@hidden>
- Date: Sat, 29 Jan 2011 16:29:53 +0100
Hi,
I am creating an aggregate object, for a project, with an initialization method:
-(id)initWithString:(id)aString {
if(![super init]) {
return nil;
}
if([aString isKindOfClass:[NSString class]]) {
self.string = (NSString *)aString;
self.attributes = nil;
}
else if ([aString isKindOfClass:[CFAString class]]) {
self.string = ((CFAString *)aString).string;
self.attributes = ((CFAString *)aString).attributes;
}
else {
CFALog(@"Type is not CFAString or NSString");
return nil;
}
return self;
}
The function runs fine and executes for passing both an NSString and a CFAString object...
I can pass any objective-c type without a warning, but when I pass my own object called CFAString (even though it is an NSObject), the following warning appears:
warning: incompatible Objective-C types 'struct CFAString *', expected 'struct NSString *' when passing argument 1 of 'initWithString:' from distinct Objective-C type
I would like to know how to fix my code, or another approach, so that this warning doesn't appear...
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden