【发布时间】:2016-12-01 12:31:48
【问题描述】:
您好,下面的代码有问题。具体来说, if let 语句将来自 NSPeristentStoreResult 的 Cast 提供给无关类型 [Item] 总是失败警告。我正在使用 Swift 3.01。
看起来这应该很简单。我正在关注的这本书是使用早期版本的 Swift 编写的。谢谢你的宽容。
func demo(){
let request = NSFetchRequest<Item>(entityName: "Item")
do {
if let items = try CDHelper.shared.context.execute(request) as? [Item] {
for item in items {
if let name = item.name {
print("Fetched Managed Object = '\(name)'")
}
}
}
} catch {
print("Error executing a fetch request: \(error)")
}
}
【问题讨论】:
标签: ios swift core-data casting swift3