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

5

6

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!

Ultramicroscopic answered 11/5, 2015 at 13:19 Comment(2)
I can copy the Realm.framework out of the RealmSwift.framework and the message disappears. But then RLMObject is not found. How about you?Flanders
This is still an issue 7years later.Insolate
V
5

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.

Viburnum answered 12/5, 2015 at 0:27 Comment(3)
Cocoapods should take care of all this. Is this a bug in the latest version?Colza
The original question was in reference to using Xcode subprojects, so CocoaPods is irrelevant. You're correct in assuming that CocoaPods takes care of all this setup, however.Viburnum
How do I find this path exactly? I'm using SPM.Interlaken
S
3

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.
Squirearchy answered 12/9, 2022 at 11:6 Comment(1)
This should be the accepted answer, because it shows a Xcode-specific solution in a clear and understandable way without relying on figuring paths manually.Finalist
C
2

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.

Craddock answered 6/6, 2015 at 20:49 Comment(0)
R
1

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.

Repairman answered 3/7, 2015 at 0:44 Comment(0)
R
0
  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
Radium answered 14/2, 2023 at 7:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.