42

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:

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

My app works properly on the previous version of Xcode(10.2.1). RealmSwiftPermissionRole is a class from the Realm and 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?

Hamed Ghadirian
  • 5,881
  • 5
  • 43
  • 65
  • If it worked in 10.2.1 and not in 11 **BETA** Then the issue is likely the fact that you're building a project on **BETA** software. I would suggest going back to 10.2.1 until 11 is official. – Jay Jun 05 '19 at 19:30
  • 1
    Not sure what you are referring to. If you have a question about why a post as up or downvoted, check out the site documentation [Why is voting important](https://stackoverflow.com/help/why-vote). I would guess that a downvote would be because *while voting down a post signals the opposite: that the post contains wrong information, is poorly researched, or fails to communicate information* and there's quite a bit of information about building apps with beta software as well as [Realm & XCode 11 beta](https://github.com/realm/realm-cocoa/issues/6163) – Jay Jun 06 '19 at 12:45

4 Answers4

94

There's an issue with iOS 13 and Xcode 11 which may cause this problem. All String properties of Realm classes with a default String value 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.

If you're using cocoa-pods:

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

pod 'RealmSwift', '~> 4.4.1'

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

pod repo update
pod install

Hope that helps.

johndpope
  • 4,597
  • 2
  • 38
  • 39
Gal Shahar
  • 2,563
  • 1
  • 16
  • 25
16

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

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.

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.

Sammy Spets
  • 261
  • 2
  • 2
10

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

@objc dynamic var id = ""
Iosif
  • 327
  • 2
  • 14
0

Try deleting and reinstalling your application too.

Mukesh Shakya
  • 417
  • 3
  • 9