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开发者_Go百科. 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?
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];
You cannot access the objects inside an NSArray
with the square bracket syntax. You have to use
[propertyValues objectAtIndex:i]
instead.
To access elements of NSArray you must use objectAtIndex:
method
for(int i = 0;i<13;i++){
[request setPostValue:[propertyValues objectAtIndex:i] forKey:[propertyKeys objectAtIndex:i]l
}
That's not now you access values in an NSArray
(which is fundamentally different than a C array).
[request setPostValue:[propertyValues objectAtInstance:i] forKey:[propertyKeys objectAtInstance:i]];
精彩评论