Object cannot be nil error

后端 未结 3 1925
臣服心动
臣服心动 2021-01-29 16:15

I am getting an error when I try to add a new object to dataArray. This is how I define dataArray.

-(NSMutableArray *)dataArray{
    i         


        
相关标签:
3条回答
  • 2021-01-29 16:50

    One of the values you're trying to insert is coming back nil, which means attributeDict does not contain either a "level" or "probability" key. The string should not be nil even if it's provided with nil arguments, they just display as (nil).

    0 讨论(0)
  • 2021-01-29 16:56

    Your argument to addObject: is likely nil.

    Test it:

    assert(attributeDict);
    assert([attributeDict objectForKey:@"level"]);
    assert([attributeDict objectForKey:@"probability"]);
    
    0 讨论(0)
  • 2021-01-29 17:05

    I fixed it. I misspelled a variable name.

    0 讨论(0)
提交回复
热议问题