gpt4 book ai didi

ios - 可以导入 RealmSwift,不能实例化

转载 作者:行者123 更新时间:2023-11-28 06:45:31 24 4
gpt4 key购买 nike

我使用 CocoaPods 安装了 RealmSwift,并且导入 RealmSwift 没有任何问题。但是,当我尝试使用它时出现了一个奇怪的错误。当我这样做时:

let realm = try! RealmSwift.Realm()

我收到这个错误:

fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=0 "Schema validation failed due to the following errors:

  • Target type 'RealmSwiftObject' doesn't exist for property 'articles'.
  • Target type 'RealmSwiftObject' doesn't exist for property 'favorites'." UserInfo={NSLocalizedDescription=Schema validation failed due to the following errors:
  • Target type 'RealmSwiftObject' doesn't exist for property 'articles'.
  • Target type 'RealmSwiftObject' doesn't exist for property 'favorites'.}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.1.101.15/src/swift/stdlib/public/core/ErrorType.swift, line 50

最佳答案

在您的类中导入 RealmSwift 之后。

你可以这样使用:

class FooClass {
let realm = try! Realm()

func bar()
{
try! realm.write {
// do stuff
}
}
}

关于ios - 可以导入 RealmSwift,不能实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36557553/

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