I am getting a warning when run an analyse in xcode in my app.
Argument to 'NSMutableArray' method 'addObject:' cannot be nil.
I am getting the error when I try to add an object to an array. Where am I going wrong?
while(sqlite3_step(statement) == SQLITE_ROW)
{
NSLog(@"sqlite3_step");
imageUrlField = ((char *)sqlite3_column_text(statement, 0))?
[NSString stringWithUTF8String
(char*)sqlite3_column_text(statement,0)]:
nil;
imageTitleField = ((char*)sqlite3_column_text(statement,1)) ?
[NSString stringWithUTF8String:
(char*)sqlite3_column_text(statement,1)] :
nil;
lat = ((char *)sqlite3_column_text(statement,2)) ?
[NSString stringWithUTF8String:
(char *)sqlite3_column_text(statement,2)] :
nil;
lon = ((char *)sqlite3_column_text(statement,3)) ?
[NSString stringWithUTF8String:
(char*)sqlite3_column_text(statement,3)]:
nil;
id1 = ((char *)sqlite3_column_text(statement,4)) ?
[NSString stringWithUTF8String:
(char *)sqlite3_column_text(statement,4)] :
nil;
visited = ((char *)sqlite3_column_text(statement,5)) ?
[NSString stringWithUTF8String:
(char *)sqlite3_column_text(statement,5)] :
nil;
if(imageUrlField == nil)
{
NSLog(@"null");
} else
{
[imageAndTitleArray addObject:imageUrlField];
[imageAndTitleArray addObject:imageTitleField];
[imageAndTitleArray addObject:lat];
[imageAndTitleArray addObject:lon];
[imageAndTitleArray addObject:id1];
[imageAndTitleArray addObject:visited];
// NSLog(@"url:%@",imageUrlField);
// NSLog(@"title:%@",imageTitleField);
// NSLog(@"lat:%@",lat);
// NSLog(@"lon:%@",lon);
// NSLog(@"lon:%@",id1);
}
}
nil
, according to your code... I would replace the[... addObject:<value>];
pattern with[... addObject:<value>?:@""];
as you'd put string anyway into the array, so like e.g. a[imageAndTitleArray addObject:lat?:@""];
– holex Apr 21 '15 at 7:52