Search code examples
objective-cnsarrayasihttprequest

Subscript requires size of interface 'NSArray', which is not constant in non-stable ABI


I'm trying to send information to a server using ASIHTTPRequest and am setting the post values like this:

    for(int i = 0;i<13;i++){
  [request setPostValue:propertyValues[i] forKey:propertyKeys[i]]    
}

propertyValues and propertyKeys are both NSArray objects that hold 13 items each. When I run this, I get the error "Subscript requires size of interface 'NSArray', which is not constant in non-stable ABI"

What does this mean?


Solution

  • It means you're trying to access an NSArray* as if it were an array, or a pointer you could do arithmetic with. x[5] for pointer types is equivalent to x + sizeof(x) * 5. Note the sizeof operator - it means the compiler needs to know the size of the type to advance the pointer by 5 "items". However, NSArray is an Objective C interface, and the compiler can't be sure what the size of the type is. This explains the wording of the error you're getting.

    More prosaically, you can't access NSArray objects like that. You need to send them a message asking for the item at a given index, thus:

    [propertyValues objectAtIndex:i];