0

what i am doing is sorting the labels for 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

1 Answer 1

1

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];
Sign up to request clarification or add additional context in comments.

2 Comments

see show a warning NSArray may not respond to insertobject:atIndex and after application will close due to "NSInternalException reason [NSCFArray insertobject:atindex]:muting meathod sent to immutable method" this will be shown inconsole
I have edited it so now the NSArray is a NSMutableArray, so you can insert Objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.