Pregunta

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]];
¿Fue útil?

Solución

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 bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top