LoginSignup
7

More than 5 years have passed since last update.

RealmSwiftをCocoaPodsで導入する

Posted at

CocoaPodsでのRealmSwiftの導入がびっくりするぐらい簡単だったのでメモ。
基本的には公式に書いてあることと一緒。
https://realm.io/jp/docs/swift/latest/

バージョン

OS X El Capitan
Swift 2.1
Xcode 7.1

CocoaPodsをインストール

$ sudo gem install cocoapods
$ pod setup

XcodeProjectにRealmSwiftをインストール

プロジェクト名は Sample とします。

ターミナル上でXcodeProjectの.xcodeprojectがあるディレクトリに移動。
以下を実行。

$ pod install

上記コマンドを実行後、Podfileが作成される。
Podfileの内容を以下のように修正。

Podfile
\# Uncomment this line to define a global platform for your project
\# platform :ios, '8.0'
\# Uncomment this line if you're using Swift
use_frameworks!

target 'Sample' do
    pod 'RealmSwift'
end

target 'SampleTests' do
    pod 'RealmSwift'
end

Podfileのあるディレクトリで以下を実行。

$ pod install

CocoaPodsによって作られた.xcworkspaceファイルを開く。

動作確認

とりあえず、RealmSwiftをインポートしてみる。

import 'RealmSwift'

このままだとエラーが表示されるが、一度ビルドを行うとエラーが消えるはず。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7