Pergunta

The following code gives an array with all Languages, still I would rather filter out variations like "en-GB",""zh-Hant" and have an array with only 2 characters per language.

What is the elegant Apple(ish) way to do so?

 NSLog(@"[NSLocale preferredLanguages] = %@",[NSLocale preferredLanguages]);
 [self.selectedArray  addObjectsFromArray:[NSLocale preferredLanguages]];
Foi útil?

Solução

Using predicates to filter arrays is probably as "Appleish" as it gets:

NSPredicate *lenIs2=[NSPredicate predicateWithFormat:@"length==2"];
NSArray *filtered = [[NSLocale preferredLanguages] filteredArrayUsingPredicate:lenIs2];
NSLog(@"%@", filtered);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top