I’m a Objective-C beginner and now I want to loop trough an array and check if the substring is in there. If true, the object of the array should be put in an other array which will be put on the screen. This is my code:
NSArray *origarray = [NSArray arrayWithObjects:
@"One",
@"Two",
@"Three",
@"Four",
@"Five",nil];
for(NSString *words in origarray){
NSMutableArray *newarray = [[NSMutableArray alloc] init];
NSRange range = [words rangeOfString:@"o"];
if(range.location != NSNotFound){
[newarray addObject:words];
}
textview.text = [newarray description];
}
In this case we should get an array of ‘One’, ‘Two’ and ‘Four’ because they both contain an ‘o’. Unfortunately I get an empty array in my textview. (I know ‘description’ is only for debugging purposes).
Is there someone who can tell me how to do this right?
You can use
NSPredicateto do that, for exampleor
for case-insensitive matching