2017-04-20 97 views
0
NSMutableArray *arrayDetails = [[NSMutableArray alloc] init]; 
CustomClass *country1  = [[CustomClass alloc] init]; 
country1.strCountryName  = @"USA"; 
country1.code    = @"12"; 
[arrayDetails addObject:country1]; 

CustomClass *country2  = [[CustomClass alloc] init]; 
country2.strCountryName  = @"India"; 
country2.code    = @"234"; 
[arrayDetails addObject:country2]; 

CustomClass *country4  = [[CustomClass alloc] init]; 
country4.strCountryName  = @"UK"; 
country4.code    = @"34"; 
[arrayDetails addObject:country4]; 

CustomClass *country5  = [[CustomClass alloc] init]; 
country5.strCountryName  = @"USA"; 
country5.code    = @"12"; 
[arrayDetails addObject:country5]; 

CustomClass *country6  = [[CustomClass alloc] init]; 
country6.strCountryName  = @"India"; 
country6.code    = @"12"; 
[arrayDetails addObject:country6]; 

CustomClass *country7  = [[CustomClass alloc] init]; 
country7.strCountryName  = @"India"; 
country7.code    = @"12"; 
[arrayDetails addObject:country7]; 

CustomClass *country8  = [[CustomClass alloc] init]; 
country8.strCountryName  = @"USA"; 
country8.code    = @"12"; 
[arrayDetails addObject:country8]; 

CustomClass *country3  = [[CustomClass alloc] init]; 
country3.strCountryName  = @"UK"; 
country3.code    = @"12"; 
[arrayDetails addObject:country3]; 


CustomClass *country77  = [[CustomClass alloc] init]; 
country77.strCountryName  = @"PAK"; 
country77.code    = @"12"; 
[arrayDetails addObject:country3]; 

我要根据国家名,其中包含和美国在一个阵列中,印度阵列中的所有英国自定义类对象的一个​​数组,使独立的套做套,甚至单个对象PAK。 数据来自服务器,基于我想要创建组的strContry名称。从数组,其中包含自定义对象的数组

+0

什么是这里的自定义类...? –

+0

只是一个模型类 –

+0

你必须使用NSPredicate来区分自定义类中的字段。我仍然没有代码。但这应该是 – ajjjjjjjj

回答

0

将所有对象添加到“arraydetails”之后,请尝试使用下面的代码来实现相同的效果。

NSArray *countryNames = [[NSOrderedSet orderedSetWithArray:[arrayDetails valueForKey:@"strCountryName"]] array]; 
    for (int i =0; i < [countryNames count]; i++) { 
     NSMutableArray *countryArray = [[NSMutableArray alloc] init]; 
     for (CustomClass *country in arrayDetails) { 
      if ([country.strCountryName isEqualToString:[countryNames objectAtIndex:i]]) { 
       [countryArray addObject:country]; 
      } 
     } 
     NSLog(@"Country array[%d] is %@", i, countryArray); 
    } 
+0

的方式是否适合你? – QUserS

相关问题