簡體   English   中英

核心數據錯誤-NSDate localizedCaseInsensitiveCompare:無法識別的選擇器發送到實例

[英]Core Data Error - NSDate localizedCaseInsensitiveCompare: unrecognised selector sent to instance

我已經搜索了過去幾個小時,但尚未找到答案。 我實現了一個AVFoundation相機,將圖像數據保存到磁盤,僅在核心數據中存儲路徑。 一切正常,但是在隨機拍攝了幾張照片后,出現此錯誤:

CoreData:錯誤:嚴重的應用程序錯誤。 在核心數據更改處理期間捕獲到異常。 這通常是NSManagedObjectContextObjectsDidChangeNotification的觀察者內部的錯誤。 -[__ NSDate localizedCaseInsensitiveCompare:]:無法識別的選擇器已發送到實例

這是我的提取請求代碼:

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Photo"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"notebook = %@", notebookItem];
[request setPredicate:predicate];
request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"dateTaken"
                                                              ascending:NO
                                                               selector:@selector(compare:)]];

這是我將數據保存在單獨的類中的方法:

//I create a photo Object to save to core data and set properties like dateTaken and tittle

//Here is where I create the path name
NSDate *dateString = [[NSDate alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
NSString *path = [formatter stringFromDate:dateString];

//Now I save to disk
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// the path to write file
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:path];
NSLog(@"path: %@", path);
[[[self captureManager] ImageDataObject] writeToFile:filePath atomically:YES];

photo.imagePath = filePath;

[notebookItem addPhotosObject:photo];
[self.SharedDocumentHandlerInstance saveDocument];

我跟蹤了崩潰的點,它發生在保存文檔的代碼行中(上面的最后一個),但也許獲取請求是導致它的原因。 我還在表中設置了self.fetchedResultsController.delegate = nil。 同樣,在隨機拍攝照片后會發生此錯誤。 感謝您的任何幫助!

您的問題是您不能在NSDate上調用localizedCaseInsensitiveCompare: :。 您需要進行更改以compare: 查看NSDate上的Apple文檔

方法localizedCaseInsensitiveCompare:需要一個NSStringApple文檔 )。

SO問題可能也有幫助。

也是此網頁中的表1 創建和使用排序描述符

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM