Context :
1 - SQLObject 协议声明了各种功能 . (我使用FMDB进行数据库访问)
protocol SQLObject {
static var tableName: String { get}
init(result: FMResultSet) throws
...
}
2 - 一些符合 SQLObject 协议的结构,实现了所需的功能
struct Foo : SQLObject {
// All protocol functions implemented - No red, no yellow here :)
}
3 - 我的应用程序中定义了一个全局数据管理器,用于从数据库中唤醒对象
class DataManager {
static let shared = DataManager()
func storedObjects<T: SQLObject>(_ type: T) throws -> [T] {
// This basically does a SELECT * and returns objects of the given type
// This is also error and warning free
}
}
Problem:
我想从应用程序的任何位置反序列化我的对象
let foos = try DataManager.shared.storedObjects(Foo)
当我构建时出现错误:
参数类型'(Foo).Type'不符合预期类型'SQLObject'
我在这里想到的东西,因为Foo实现了SQLObject协议 . 任何解释,编码伙伴?