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

耗尽温柔 提交于 2019-12-10 21:53:21

问题


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?


回答1:


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];



回答2:


You cannot access the objects inside an NSArray with the square bracket syntax. You have to use

[propertyValues objectAtIndex:i]

instead.




回答3:


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    
}



回答4:


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]];


来源:https://stackoverflow.com/questions/6228132/subscript-requires-size-of-interface-nsarray-which-is-not-constant-in-non-sta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!