我想在Core Data項目(Swift)上實現狀態恢復,並且在分割視圖控制器中的UITableView的數據源上實現UIDataSourceModelAssociation協議時出現問題,這是一個圍繞NSFetchedResultsController的包裝類。 的代碼是:Xcode 8.1 UIDataSourceModelAssociation破裂了嗎?
1 extension EventDataProvider : UIDataSourceModelAssociation
2 {
3 public func modelIdentifierForElement(at idx: IndexPath, in view: UIView) -> String?
4 {
5 let elementAtIndexPath = self.fetchedResultsController.object(at: idx)
6
7 return String(describing: elementAtIndexPath.objectID.uriRepresentation())
8 }
9 public func indexPathForElement(withModelIdentifier identifier: String, in view: UIView) -> IndexPath?
10 {
11 if let url = URL(string: identifier),
12 let objectID = self.fetchedResultsController.managedObjectContext.persistentStoreCoordinator?.managedObjectID(forURIRepresentation: url),
13 let object = self.fetchedResultsController.managedObjectContext.object(with: objectID) as? CDEvent
14 {
15 return self.fetchedResultsController.indexPath(forObject: object) as NSIndexPath?
16 }
17
18 return nil
19 }
20 }
我正在一個EXC_BAD_INSTRUCTION例外,停止調試器在AppDelegate類的頂部,在狀態恢復這似乎指向與「靜態Foundation.IndexPath._unconditionallyBridgeFromObjectiveC問題(Swift.Optional < __ObjC.NSIndexPath>) - > Foundation.IndexPath「。
我用restorationArchiveTool所得到的data.data文件從savedState文件夾轉換爲用命令的plist」 .../restorationArchiveTool --plist --structured -o路徑/到/ OUTPUTFILE
如果我查看與預覽所得plist文件,我得到以下:
kApplicationSelectedCellIndexPathsKey ...( 「< NSIndexPath:0x7fe60054cb00 > {長度= 2,路徑= 0 - 3}」)
...但如果我在Xcode中打開plist,我會得到以下內容:
kApplicationSelectedCellIndexPathsKey爲重點,但只有(該值
。假定解碼器將相同的算法的plist讀卡器,用於將數據文件,它不會令人感到意外得到某種異常。
如果我刪除了UIDataSourceModelAssociation擴展,則異常消失。
其他人可以證實這個問題,或者我錯過了一些非常明顯的東西嗎?