开发者

how to assign string array values to variable

开发者 https://www.devze.com 2023-01-10 15:34 出处:网络
what i am doing is sorting the labels fo开发者_StackOverflow中文版r that i am assigning the string array to temporary string variableas follows:

what i am doing is sorting the labels fo开发者_StackOverflow中文版r that i am assigning the string array to temporary string variable as follows:

NSString *tmp = [labels objectAtIndex:j-1];
labels[j-1]=labels[j];
labels[j] = tm;

but it shows error at last line that is incomplete types in assignment how can i solve this?

thank you


Labels is not a C array, it's and Objective-C array, so you need to do

NSMutableArray *labels2 = [[NSMutableArray alloc] initWithArray:labels];
NSString *tmp = [labels objectAtIndex:j-1];
[labels2 insertObject:[labels objectAtIndex:j] atIndex:j-1];
[labels2 insertObject:tm atIndex:j];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号