这是我的DBManager. swift import RealmSwiftclass DBManager { class func getAllDogs() - [Dog] { let realm = try! Realm() // COMPILER ERROR: Cannot Convert value of type 'Dogs.Type' to expected argument type 'T.Type' return realm.objects(D
import RealmSwift class DBManager { class func getAllDogs() -> [Dog] { let realm = try! Realm() // COMPILER ERROR: Cannot Convert value of type 'Dogs.Type' to expected argument type 'T.Type' return realm.objects(Dog.self) } }
这是我的Dog.swift:
import Foundation import RealmSwift class Dog: Object { dynamic var firstName = "" dynamic var lastName = "" dynamic var dateOfBirth = "" dynamic var lastFourSsn = "" dynamic var currentLocation = "" dynamic var dog: NSData! }
我收到此编译器错误:
Cannot Convert value of type ‘Dogs.Type’ to expected
argument type ‘T.Type’
好像我在这里遗漏了一些非常基本的东西 – 因为这主要是直接来自RealmSwift documentation的代码.我做错了什么?
realm.objects(Dog.self)返回结果< Dog> ;,而不是Array< Dog> (a.k.a. [狗]).误导性错误消息可能只是编译器未能很好地报告确切类型错误发生的位置.