plist에서 생성 된 사전의 다른 배열에 대한 필터로 사용하려는 문자열 배열이 있습니다.iOS는 배열이있는 배열을 필터링합니다.
Key: Value:
car1 audi
car2 bmw
car3 bmw
car4 audi
car5 jaguar
문자열의 내 배열 "아우디, 재규어은"이었다 예를 들어, 만약 내가 지금처럼 보였다 사전 PLIST했다. "car1, car4, car5"를 반환하는 새로운 배열을 만들 수 있도록 어떻게 코드합니까? 희망이 의미가 있습니다. 또는 더 나은 방법은,이 사전을 걸어 내려 가서 값을 기준으로 필터링 한 다음 사용할 새 사전 배열을 만드는 방법입니다.
코드 :
-(void)plotStationAnnotations {
desiredDepartments = [[NSMutableArray alloc] init];
BOOL tvfrSwitchStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"tvfrSwitchStatus"];
BOOL hfdSwitchStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"hfdSwitchStatus"];
if (tvfrSwitchStatus) {
NSString *tvfr = @"TVF&R";
[desiredDepartments addObject:tvfr];
}
if (hfdSwitchStatus) {
NSString *hfd = @"HFD";
[desiredDepartments addObject:hfd];
}
NSLog(@"Array 1 = %@", desiredDepartments);
NSString *path = [[NSBundle mainBundle] pathForResource:@"stationAnnotations" ofType:@"plist"];
NSMutableArray *anns = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSMutableArray *newDictionaryArray = [NSMutableArray array];
for (NSDictionary *dictionary in anns) {
for (NSString *string in desiredDepartments) {
if ([dictionary allKeysForObject:string]) {
[newDictionaryArray addObject:dictionary];
break;
}
}
}
NSLog(@"Array = %@", keyMutableArray);
for (int i = 0; i < [keyMutableArray count]; i++) {
float realLatitude = [[[keyMutableArray objectAtIndex:i] objectForKey:@"latitude"] floatValue];
float realLongitude = [[[keyMutableArray objectAtIndex:i] objectForKey:@"longitude"] floatValue];
StationAnnotations *myAnnotation = [[StationAnnotations alloc] init];
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = realLatitude;
theCoordinate.longitude = realLongitude;
myAnnotation.coordinate = theCoordinate;
myAnnotation.title = [[keyMutableArray objectAtIndex:i] objectForKey:@"station"];
myAnnotation.subtitle = [[keyMutableArray objectAtIndex:i] objectForKey:@"department"];
[mapView addAnnotation:myAnnotation];
}
}
'사전'은 어디에 있습니까? 나는 여러 사전들을 가지고있다. 그래서 나는 그렇게 할 수 있을까? –
사전에 배열이 있다고 말하면 무슨 뜻인지 모르겠다. plist는 위의 하나의 사전에 제공 한 키와 값을 가진 하나의 사전이어야한다. 위에 제시 한 각 값/키가 별도의 사전에 있습니까? 그렇다면 사전 배열이 아니라 하나의 사전에 보관해야합니다. –
약 30 개의 사전으로 구성되어 있습니다. 각 사전에는 4 개의 요소가 있습니다. –