gpt4 book ai didi

ios - 类型 'Self.ManageableType' 的值没有成员 'uid'

转载 作者:行者123 更新时间:2023-11-29 01:15:17 24 4
gpt4 key购买 nike

这是我的代码,它是在 XCode 7.2.1 中构建的。当我尝试在 XCode 7.3 beta 2 中构建项目时,出现错误“‘Self.ManageableType’类型的值没有成员‘uid’”

protocol Manageable {
typealias ManageableType : NSManagedObject
var uid: String { get set }
}

extension Manageable {

static func className() -> String {
return String(self)
}

static func fetchObjects(predicate: NSPredicate?,
completion:(fetchedObjects: [String: ManageableType]) -> ()) {
let entityDescription = NSEntityDescription.entityForName(className(),
inManagedObjectContext: CoreDataStack.sharedInstance.context)
let fetchRequest = NSFetchRequest()
fetchRequest.entity = entityDescription
if let p = predicate {
fetchRequest.predicate = p
}
var fetchedObjectsDict: [String: ManageableType] = [:]
do {
let result = try CoreDataStack.sharedInstance.context.executeFetchRequest(fetchRequest) as! [ManageableType]
if result.count > 0 {
for object in result {
fetchedObjectsDict[object.uid] = object
}
}
} catch {
print("ERROR FETCH MANAGEABLE OBJECTS: \(error)")
}
completion(fetchedObjects: fetchedObjectsDict)
}
}

当我尝试将循环代码块更改为:

for object in result {
let uid = object.valueForKey("uid") as! String
fetchedObjectsDict[uid] = object
}

我收到错误消息“‘valueForKey’的使用不明确”

为什么在新的 XCode 版本中会出现这些错误,请帮忙?

最佳答案

你的协议(protocol)扩展需要一个类型约束

extension Manageable where Self : NSManagedObject, ManageableType == Self { ... }

关于ios - 类型 'Self.ManageableType' 的值没有成员 'uid',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35256933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com