[英]Xcode 6 Beta 4: Use of Unresolved Identifier 'NSFetchedResultsChangeInsert'
剛剛安裝了Xcode 6 Beta 4,之前編譯的代碼現在在NSFetchedResultsChangeType的每個開關上都有“Unresolved Identifier”失敗。 我檢查了發行說明,當然還要通過這里搜索,看看是否有其他人經歷過這個,但到目前為止還沒有任何結果。 任何信息表示贊賞!
謝謝!
func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {
println("Running CoreDataTVC.controllerDidChangeSection")
switch type {
case NSFetchedResultsChangeInsert:
self.tableView.insertSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
case NSFetchedResultsChangeDelete:
self.tableView.deleteSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
default:
return
}
}
當枚舉時
typedef NS_ENUM(NSUInteger, NSFetchedResultsChangeType) {
NSFetchedResultsChangeInsert = 1,
NSFetchedResultsChangeDelete = 2,
NSFetchedResultsChangeMove = 3,
NSFetchedResultsChangeUpdate = 4
} ;
映射到Swift,從枚舉值中自動刪除公共前綴:
enum NSFetchedResultsChangeType : UInt {
case Insert
case Delete
case Move
case Update
}
比較“使用Swift with Cocoa和Objective-C”文檔中的“ 與C API交互 ”。
所以你的代碼應該是這樣的
func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {
switch type {
case .Insert:
self.tableView.insertSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
case .Delete:
self.tableView.deleteSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
default:
return
}
}
提示:如果您在Xcode中創建了一個“主 - 細節”應用程序並選擇了“使用核心數據”,您將獲得可以開始的示例代碼。
枚舉NSFetchedResultsChangeType在NSFetchedResultsController內定義。
enum NSFetchedResultsChangeType : UInt {
case Insert
case Delete
case Move
case Update
}
要訪問枚舉值,您可以使用枚舉類型,然后使用如下情況:
switch type {
case NSFetchedResultsChangeType.Insert:
self.tableView.insertSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
case NSFetchedResultsChangeType.Delete:
self.tableView.deleteSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
default:
return
}
既然你知道Type的類型是NSFetchedResultsChangeType
你也可以從switch case中省略它,只是用case .Insert:
和case .Delete:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.