2016-01-07 36 views
2

我正在使用核心數據並基於ID數組獲取結果。這個ID數組是我需要獲取的序列。但是取得的結果不是這樣的順序。我應該怎麼做才能獲取完全匹配ID數組順序的對象?Coredata提取請求與序列順序

// get manageObjectContext 
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
NSManagedObjectContext *context = [appDelegate managedObjectContext]; 

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SomeName" 
              inManagedObjectContext:context]; 
[fetchRequest setEntity:entity]; 

fetchRequest.predicate = [NSPredicate predicateWithFormat:@"%K IN %@", @"anId", arr]; 

NSError *error; 
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error]; 
fetchRequest = nil; 

回答

-1

使用

fetchRequest.sortDescriptors = NSSortDescriptor(key: "anId", ascending: true or false) 
+0

其未按升序排列,順序不同 – sajaz

+0

的.sort({$ 0.property> $ 1.property})如果你想有一個特定的順序是什麼呢? –