문제

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]];
도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top