Here is the code:
ComicDB * newComic = (ComicDB *)[NSEntityDescription insertNewObjectForEntityForName:@"ComicDB" inManagedObjectContext:context];
[newComic setValue:comic.iComicId forKey:@"ComicID"];
[newComic setValue:comic.sImage forKey:@"Image"];
[newComic setValue:comic.sName forKey:@"Name"];
[newComic setValue:comic.sText forKey:@"Text"];
[newComic setValue:comic.sComicURL forKey:@"URL"];
This was the warning i got on the setValue:comic.iComicId forKey@"ComicID"
. FYI - comic is my own class that holds comic details.
warning: passing argument 1 of 'setValue:forKey:' makes pointer from integer without a cast
when i change the line of code to:
[newComic setValue:[comic.iComicId intValue] forKey:@"ComicID"];
i get these warnings and an error: warning: invalid receiver t开发者_开发百科ype 'int' warning: passing argument 1 of 'setValue:forKey:' makes pointer from integer without a cast
What am i doing wrong?
If comic.iComicId
is not an NSNumber
, you need to wrap it in an NSNumber
object then pass it:
[newComic setValue:[NSNumber numberWithInt:[comic.iComicId intValue]] forKey:@"ComicID"];
精彩评论