xcode 对象“RealmSwiftPermissionRole”上不存在主键属性“name”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56457524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:57:08  来源:igfitidea点击:

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

xcoderealm

提问by Hamed Ghadirian

I'm using RealmSwift as a database in my swift project. Today, after opening my project in Xcode-beta version 11, my app crash with this error:

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

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

由于未捕获的异常“RLMException”而终止应用程序,原因:“主键属性“名称”在对象“RealmSwiftPermissionRole”上不存在

My app works properly on the previous version of Xcode(10.2.1). RealmSwiftPermissionRoleis a class from the Realmand I don't have access to it. Maybe in their feature updates, they fix this bug but for now, I search a lot but didn't find any solution. (I clean the project, delete the app from the simulator, and run the project again but nothing changed.) Any suggestion?

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

回答by Gal Shahar

There's an issue with iOS 13 and Xcode 11 which may cause this problem. All String properties of Realm classes with a default Stringvalue set are disregarded somehow. You can fix this by updating to the latest version (currently 3.20.0) and then on Xcode: Product -> Clean Build Folder.

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

If you're using cocoa-pods:

如果您使用可可豆荚:

Open your project's Podfile, and replace RealmSwift line with:

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

pod 'RealmSwift', '~> 3.20.0'

Then, open terminal on the project's folder and:

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

pod repo update
pod install

Hope that helps.

希望有帮助。

回答by Sammy Spets

Developers of Realm have started working on Xcode 11 compatibility. From that page...

Realm 的开发人员已经开始致力于Xcode 11 兼容性。从那个页面...

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 与 Xcode 测试版一起使用需要从源代码构建,并且通常需要使用开发分支而不是发布。

迦太基

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

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

可可豆

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

需要明确包含 Realm pod 作为依赖项,否则它将尝试使用最新版本的 obj-c 部分。

Note that last sentence. You must include the Realm pod as a dependency or it'll use the non-beta version and it won't work.

注意最后一句。您必须将 Realm pod 作为依赖项包含在内,否则它将使用非 beta 版本并且无法运行。

回答by Iosif

I had run into the same issue with RealmSwift 4.3.1, the problem was I forgot to mark the property as @objc

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

@objc dynamic var id = ""

回答by Mukesh Shakya

Try deleting and reinstalling your application too.

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