iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 21
0
Mobile Development

IOS App開發學習日誌系列 第 21

D21 CocoaPods

今天要介紹CocoaPods,我們可以使用這個第三方庫資源相依性管理工具來安裝第三方套件

安裝CocoaPods

安裝CocoaPods的步驟相當簡單,只要到終端機(terminal)輸入
sudo gem install cocoapods
接著輸入密碼,等待安裝完成即可。

在project中使用CocoaPods

首先,建立一個專案叫TestPods,接著到終端機cd進到這個專案
cd Desktop/TestPods
接著我們必須建立一個podfilepodfile就是用來管理我們所需的套件
在專案底下輸入以下指令:
pod init
之後便會產生一個podfile,如下

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

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

  # Pods for podTest

end

安裝第三方套件

接著就是要安裝需要的套件了,今天我來安裝一個容易上手的資料庫Realm
開啟podfile,將內文改成以下或是在

target ‘TestPods’ do
 pod 'RealmSwift'
end
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '3.0'
    end
  end
end

最後在終端機中輸入以下指令:
pod install
CocoaPods便會開始安裝在podfile中所指定的套件,安裝完會在專案資料夾下產生一個podTest.xcworkspace的workspace檔案,之後開啟專案就必須開啟這個檔案而不是.xcodeproj檔,明天會接著介紹Realm


上一篇
D20 CAShapeLayer&UIBezierPath
下一篇
D22 Realm(一)
系列文
IOS App開發學習日誌30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言