2013-01-08 23 views
2

我使用MagicalRecord library,使其更容易與CoreData的工作纔剛剛開始。我使用的是FRC,不能弄清楚如何使用自定義sortDescriptor設置了諸如CoreData:使用MagicalRecord與FetchedResultsController和一個自定義sortDescriptor

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] 
         initWithKey:@"someAttribute" 
          ascending:YES 
          selector:@selector(localizedCaseInsensitiveCompare:)]; 

目前我調用來檢索FRC是這樣的:

_fetchedResultsController = [Language MR_fetchAllSortedBy:@"someAttribute" 
               ascending:YES 
              withPredicate:nil 
                groupBy:nil 
               delegate:self]; 

似乎就像我正在尋找的方法是「簡單地」將一個自定義選擇器添加到MR_fetchAllSortedBy。就像:

_fetchedResultsController = 
     [Language MR_fetchAllSortedBy:@"someAttribute" 
          ascending:YES 
          selector:@selector(localizedCaseInsensitiveCompare:) 
         withPredicate:nil 
          groupBy:nil 
          delegate:self]; 

任何人都可以給我一些關於如何實現這一目標的指針嗎?使用類別可能嗎?

由於提前,

喬斯。

回答

0

今天我有完全相同的問題。您無法通過MR_FindAll方法設置自定義排序描述符,但您可以創建自己的提取請求,同時仍利用魔法記錄樣板代碼:

NSFetchRequest *fetchRequest = [Sites MR_createFetchRequest]; 
fetchRequest.sortDescriptors = @[[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]]; 

self.sitesArray = [NSManagedObject MR_executeFetchRequest:fetchRequest]; 
相關問題