gpt4 book ai didi

ios - Realm iOS : Cannot Convert value of type 'Dogs.Type' to expected argument type 'T.Type'

转载 作者:搜寻专家 更新时间:2023-10-31 21:59:40 34 4
gpt4 key购买 nike

这是我的 DBManager.swift

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)返回 Results<Dog> , 不是 Array<Dog> (又名 [Dog] )。误导性错误消息可能只是编译器未能很好地报告发生类型错误的确切位置。

关于ios - Realm iOS : Cannot Convert value of type 'Dogs.Type' to expected argument type 'T.Type' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39500825/

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