开发者

NSDateFormatter Incompatible Type Error

I am receiving the followi开发者_高级运维ng error in Xcode:

warning: incompatible Objective-C types 'struct NSDate *', expected 'struct NSString *' when passing argument 1 of 'setUpdate:' from distinct Objective-C type

The error happens when I am trying to save the formatted string to myObj.update

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
//myObj is an object with instance variable 'update' as a NSString string
myObj.update = [formatter dateFromString:@"2011-03-17T18:15:05Z"];
[formatter release];

I know I am doing something wrong that is minor but can't pinpoint. Thanks for the help! :)


dateFromString: returns an instance of NSDate, not a string. You need to make your update property an NSDate. The compiler is basically telling you that the method is returning a date, but you're trying to assign that to a string property, and that's just not gonna be healthy!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜