I would like to loop through an NSString and call a custom function on every word that has certain criterion (For example, “has 2 ‘L’s”). I was wondering what the best way of approaching that was. Should I use Find/Replace patterns? Blocks?
-(NSString *)convert:(NSString *)wordToConvert{
/// This I have already written
Return finalWord;
}
-(NSString *) method:(NSString *) sentenceContainingWords{
// match every word that meets the criteria (for example the 2Ls) and replace it with what convert: does.
}
The two ways I know of looping an array that will work for you are as follows:
and
The other method,
–makeObjectsPerformSelector:withObject:, won’t work for you. It expects to be able to call[word method:obj]which is backwards from what you expect.