Cannot import RealmSwift in XCode 11.1

I am taking an online course and I got to a section about Realm and saving data.

I downloaded the zip file,. selected the files needed for XCode 11.1 and dragged them into the Frameworks, Libraries and Embedded Content section. When I type "import RealmSwift" is isn't recognized...

I am following the exact steps in the course, so I have no idea what is wrong here. Any suggestions?

Since you didn't specify which exact instructions (which files are needed?) you used to install Realm, it's hard to help you for this approach.

But if you can't do it with the courses instructions, it's always good to take a look at the projects page itself and see what they suggest to do (

The simplest variant would be to just use the Swift Package Manager. For that in Xcode go to File -> Swift Packages -> Add Package Dependecy... Then enter the link to the Realm GitHub repository and you're ready to go.

Thanks, @columbbus.

Unfortunately, none of that worked. I went through the steps on the realm website as well. I am a beginner, so this is all complicated to me at the moment.

In my video course, all the instructor had to do was download the files from the Realm site, drag them into XCode and everything worked. No extra steps.

These are the iOS files I downloaded and dragged into the "Frameworks, Libraries and Embedded Content" section in XCode....

So you say it didn't work with the Swift Package Manager as well? That would be strange.

Another note on your approach: Normally you don't add frameworks to your Project by just copying them in your project directory, because it's hard to maintain. You would always need to manually download the framework again in there are updates. That's why you would want to use package managers like CocoaPods, Carthage or Swift Package Manager.

Back to your issue. When dragging the framework into the "Frameworks, Libraries and Embedded Content" section, you also need to make sure, that the framework is included in your project. When dragging a framework from the outside of the project directory (for example ~/Downloads) into the project, the framework is only referenced and not copied.

So there are two solutions:

  1. Move the frameworks into the project tree in Xcode (for example in a Group named "Frameworks") and check "Copy items if needed". Like that, the framework is copied to your project directory and should be added automatically to "Frameworks, Libraries and Embedded Content". If not you can add the frameworks using the "+" button.
  2. If you want your framework to stay where it is (outside the projects directory) you have to tell Xcode where it is. Therefore in your project settings go to Build Settings and search for "Framework Search Paths". There you can add the directory, where you framework is in.

Thank you, @columbbus.

It turns out that the problem was that the framework was not included in my project. I was not prompted to select "Copy if needed" like the course video showed (probably because I have a different version of XCode). Not knowing what that meant or what it did, I didn't realize that it copies and pastes the Realm files into the project folder for you. I had no idea that I had to do that manually. I pasted the files in myself, and all is working as it should.

I appreciate the help!