Help us understand the problem. What is going on with this article?

RealmSwiftをCocoaPodsで導入する

More than 3 years have passed since last update.

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'

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away