API MISUSE(APPLE)对NSMutableArray'的争论方法' addObject:'不能为零

时间:2015-04-21 06:27:12

标签: ios iphone ios7 ios5 ios8

在我的应用中运行xcode中的分析时,我收到警告。

  

'NSMutableArray'方法'addObject:'的参数不能为零。

当我尝试将对象添加到数组时,我收到错误。我哪里错了?

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);
            }

        }

1 个答案:

答案 0 :(得分:1)

您无法在NSMutableArray中添加nil,因此如果您的字符串实例为nil并且您尝试在NSMutableArray中添加它们,则会出现上述错误API Misuse {{1 }}

在将字符串添加到

之前,您应该检查字符串是否为nil
(API MISUSE(APPLE) Argument to 'NSMutableArray' method 'addObject:' cannot be nil)

如果您需要在NSMutableArray as if(imageUrlField != nil) [imageAndTitleArray addObject:imageUrlField]; if(imageTitleField != nil) [imageAndTitleArray addObject:imageTitleField]; if(lat != nil) [imageAndTitleArray addObject:lat]; //like so for others if(visited != nil) [imageAndTitleArray addObject:visited]; 中添加null,则可以使用NSMutableArray