user3181273
user3181273

Reputation:

Adding RealmSwift as a subproject: Missing required modules: 'Realm.Private', 'Realm'

So I wanted to link to RealmSwift in my own framework and these are the steps I took:

  1. Add RealmSwift as a subproject

    enter image description here

  2. Link the framework:

    enter image description here

  3. Add the dependency

    enter image description here

  4. Import RealmSwift into the Swift file:

    enter image description here

And I got the error: Missing required modules: 'Realm.Private', 'Realm'. How can I solve this issue? Thanks!

Upvotes: 6

Views: 5778

Answers (5)

Abhi Mitra
Abhi Mitra

Reputation: 1

  1. Select Project Name.
  2. Navigate to Build Phases > Link Binary With Libraries enter image description here
  3. Click the plus sign to add > Select Realm, RealmSwift click Add enter image description here
  4. Hit command + b to build and your problem should go away like this image

Upvotes: 0

Raahs
Raahs

Reputation: 110

I had the same issue, turns out that the file that showed the error was used by two different targets. When adding Realm with SPM, we can only select one target. I solved the with the following steps:

  1. In the Project Navigator, select the target that lacks Realm
  2. In Build Phases > Link Binary With Libraries, add RealmSwift and Realm.

Upvotes: 3

Mike Kirkwood
Mike Kirkwood

Reputation: 56

Something similar happened to me when I did the pod install...

Make sure you open the appname.xcworkspace file not the appname.xcodeproj after doing the pod-install with CocoaPods.

The error No such module 'RealmSwift' will occur from any file where 'import RealmSwift' is set up if not opened from appname.xcworkspace.

Upvotes: 1

Oran Dennison
Oran Dennison

Reputation: 3297

As of Realm v0.93.0, RealmSwift.framework no longer embeds Realm.framework. This causes the same missing module error message when you upgrade. You can resolve it by linking directly to both RealmSwift.framework and Realm.framework. You'll also need to remove any pre-existing strip-frameworks.sh Run Script Phase in your app's target's Build Phases. This step is no longer needed.

Upvotes: 2

jpsim
jpsim

Reputation: 14409

You'll need to add /path/to/RealmSwift.framework/Frameworks to the “Framework Search Paths” section in Build Settings

where /path/to/RealmSwift.framework is the location of the framework.

This is because RealmSwift.framework depends on Realm.framework (where the Realm and Realm.Private modules are defined), which is vendored in its Frameworks directory.

Upvotes: 5

Related Questions