Navigation

Install Realm for iOS, macOS, tvOS, and watchOS

Overview

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.

Prerequisites

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.6.0 or later.

Installation

Follow these steps to add the MongoDB Realm Apple platform SDK to your project.

1

Update the CocoaPods repositories

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

2

Initialize CocoaPods for Your Project

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 Realm as a Dependency in Your Podfile

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

Add the line pod 'RealmSwift', '=10.0.0-beta.2' 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.0.0-beta.2'

end

Add the line pod 'Realm', '=10.0.0-beta.2' to your main and test targets.

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

When done, your Podfile should look something like this:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'MyRealmProject' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for MyRealmProject
pod 'Realm', '=10.0.0-beta.2'

target 'MyRealmProjectTests' do
   inherit! :search_paths
   # Pods for testing
   pod 'Realm', '=10.0.0-beta.2'
end

end
4

Install the Dependencies

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

5

Use the CocoaPods-Generated .xcworkspace File

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.

Import Realm

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

import RealmSwift
#import <Realm/Realm.h>