Navigation

Install Realm for iOS, macOS, tvOS, and watchOS

MongoDB Realm's Apple platform SDK enables your iOS, macOS, tvOS, and watchOS applications to interact with MongoDB Realm using either the Swift or Objective-C programming languages. This page details how to install Realm in your project and get started.

Before getting started, ensure your development environment meets the following prerequisites:

  • Xcode version 10.0 or higher.
  • Target of iOS 8.0 or higher, macOS 10.9 or higher, tvOS 9.0 or higher, or watchOS 2.0 or higher.
  • If you are installing with CocoaPods, you need CocoaPods 1.10.0 or later.

Follow the procedure for either SwiftPM or CocoaPods below to add the MongoDB Realm Apple platform SDK to your project.

1

In Xcode, select File > Swift Packages > Add Package Dependency.

2

Copy and paste the following into the search/input box, then click Next.

https://github.com/realm/realm-cocoa.git
3

Leave the default value of Up to Next Major, then click Next.

4

Select both Realm and RealmSwift, then click Finish.

1

On the command line, run pod repo update to ensure CocoaPods can access the latest available Realm versions.

2

If you do not already have a Podfile for your project, run pod init in the root directory of your project to create a Podfile for your project. A Podfile allows you to specify project dependencies to CocoaPods.

3

Add the line use_frameworks! if it is not already there.

Add the line pod 'RealmSwift', '=10.1.4' to your main and test targets.

When done, your Podfile should look something like this:

platform :ios, '12.0'
target 'MyRealmProject' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for MyRealmProject
pod 'RealmSwift', '=10.1.4'
end
4

From the command line, run pod install to fetch the dependencies.

5

CocoaPods generates an .xcworkspace file for you. This file has all of the dependencies configured. From now on, open this file -- not the .xcodeproj file -- to work on your project.

Add the following line at the top of your source files to use MongoDB Realm:

import RealmSwift
Give Feedback