2013-03-23 17 views
6

'a göre hesaplamalıdır. Aslında ne saklıyorum, her sözlük nesnesinde farklı veri tipine sahip olan bu veri türünde tüm veri türlerini bir string olarak alarak bu dize türünü belirli bir veri türüne dönüştürüp fiyat mengene, kodum ve çıkışım feryat olsun lütfen Bunun için bana yardım et.IOS, sözlük nesnesini kullanarak anahtarlara dayalı değerleri sıralamak için sorunlu bir anahtar kelime değeri dizisini

-(IBAction)PriceSort:(id)sender 
{ 
    NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:@"Price" ascending:true] ; 
    NSArray *sa = [symbolArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]]; 
    NSLog(@"price=%@",sa); 

} 

üzerinden {bu yardımcı olur

volume = 2496752; 

    Yield = "10.49"; 

    MarCap = 829; 

    Price = "0.715"; 

    Symbol = SAIPI; 

}, 
+0

Sözlükteki ne kadar farklı veri türleri, bunları gösterebilir misiniz? –

cevap

10
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"price" 
               ascending:YES selector:@selector(localizedStandardCompare:)] ; 

Lütfen bunu yenisiyle değiştirin ve çalışmalarını deneyin.

+0

çalışmalarını cezalandırmak teşekkür ederim – Vijay

4
-(void)sort 
{ 
    //This is the array of dictionaries, where each dictionary holds a record 
    NSMutableArray * array; 
    //allocate the memory to the mutable array and add the records to the arrat 

    // I have used simple bubble sort you can use any other algorithm that suites you 
    //bubble sort 
    // 
    for(int i = 0; i < [array count]; i++) 
    { 
     for(int j = i+1; j < [array count]; j++) 
     { 
      NSDictionary *recordOne = [array objectAtIndex:i]; 
      NSDictionary *recordTwo = [array objectAtIndex:j]; 

      if([[recordOne valueForKey:@"price"] floatValue] > [[recordTwo valueForKey:@"remaining"] floatValue]) 
      { 
       [array exchangeObjectAtIndex:i withObjectAtIndex:j]; 
      } 
     } 
    } 

    //Here you get the sorted array 
} 

Umut koydu.

+0

Teşekkür ederim kunal – Vijay

İlgili konular