对象 'RealmSwiftPermissionRole' 上不存在主键 属性 'name'

Primary key property 'name' does not exist on object 'RealmSwiftPermissionRole'

我在 swift 项目中使用 RealmSwift 作为数据库。今天,在 Xcode-beta 版本 11 中打开我的项目后,我的应用程序崩溃并出现以下错误:

Terminating app due to uncaught exception 'RLMException', reason: 'Primary key property 'name' does not exist on object 'RealmSwiftPermissionRole''

我的应用程序在以前版本的 Xcode(10.2.1) 上运行正常。 RealmSwiftPermissionRole 是来自 Realm 的 class,我无权访问它。也许在他们的功能更新中,他们修复了这个错误,但就目前而言,我搜索了很多但没有找到任何解决方案。 (我清理项目,从模拟器中删除应用程序,然后再次 运行 项目但没有任何改变。) 有什么建议吗?

尝试删除并重新安装您的应用程序。

Realm 的开发者已经开始 Xcode 11 compatibility。从那个页面...

Using Realm with Xcode betas requires building from source, and typically will require using dev branches rather than releases.

Carthage

github "realm/realm-cocoa" "tg/xcode-11-b1"

DEVELOPER_DIR=/Applications/Xcode-beta.app/Contents/Developer carthage bootstrap -no-use-binaries

CocoaPods

pod 'Realm', git: 'https://github.com/realm/realm-cocoa.git', branch: 'tg/xcode-11-b1', submodules: true

pod 'RealmSwift', git: 'https://github.com/realm/realm-cocoa.git', branch: 'tg/xcode-11-b1', submodules: true

Explicitly including the Realm pod as a dependency is required as otherwise it'll try to use the latest release of the obj-c part.

注意最后一句话。您必须将 Realm pod 作为依赖项包含在内,否则它将使用 non-beta 版本并且无法正常工作。

iOS 13 和 Xcode 11 存在问题,可能会导致此问题。具有默认 String 值集的 Realm 类 的所有字符串属性都以某种方式被忽略。 您可以通过更新到最新版本(当前为 3.20.0)然后在 Xcode 上修复此问题:Product -> Clean Build Folder.

如果您使用 cocoa-pods:

打开项目的 Podfile,并将 RealmSwift 行替换为:

pod 'RealmSwift', '~> 4.4.1'

然后,在项目文件夹中打开终端并:

pod repo update
pod install

希望对您有所帮助。

我在 RealmSwift 4.3.1 遇到了同样的问题 运行,问题是我忘记将 属性 标记为 @objc

@objc dynamic var id = ""