見出し画像

Swiftで行こう!--CocoaPodsでRealm!

ターミナルを立ち上げ、コマンドラインを使います。

$ cd プロジェクトのあるディレクトリ名

な感じでまずディレクトリに移ります。例えば、testフォルダにプロジェクトがあり、デスクトップにフォルダがあるとすると、

$ cd /Users/ns/Desktop/test

ですね。移動したら次は、

$ pod init

すると

"Podfile"ができているはずです。中身は

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'test' do
 # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
 use_frameworks!
 # Pods for test
 target 'testTests' do
   inherit! :search_paths
   # Pods for testing
 end
 target 'testUITests' do
   inherit! :search_paths
   # Pods for testing
 end
end

となっています。データベースを比較的簡単に使えるライブラリRealmを使えるように取り込むために編集します。

 target 'test' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for test
  pod 'RealmSwift'
 end

と修正して

$ pod install

すると、

こんな感じでファイルが出来上がっています。プロジェクトの開発をするときは"test.xcworkspace"をダブルクリックで起動して行います。

左側に新しいファイル、フォルダができています。そして,

import RealmSwift

と書いてうまくビルド(⌘B)が通れば成功です。

この記事が気に入ったらサポートをしてみませんか?