How to turn an NSArray of strings into an array of unique strings, in the same order?

前端 未结 5 2021
我在风中等你
我在风中等你 2020-12-23 17:34

If you have an NSArray of strings

{ @\"ONE\", @\"ONE\", @\"ONE\", \"TWO\", @\"THREE\", @\"THREE\" }

How would I turn that into

<         


        
5条回答
  •  醉话见心
    2020-12-23 17:42

    Hmm.. you could just use a loop ?

    NSMutableArray *newarray = [[NSMutableArray alloc] init];
    NSString *laststring = nil;
    for (NSString *currentstring in oldarray) 
    {
       if (![currentstring isEqualtoString:laststring]) [newarray addObject:currentstring];
       laststring = currentstring
    }
    

提交回复
热议问题