Introdução ao CocoaPods

Introdução ao CocoaPods

xcode 強大 framework / Library 管理 工具, 很多 github 上 的 強大 專案 也 都有 使用,
大 部份 都會 在 Installation 教學 使用 podfile 的 方法
學習 CocoaPods 不只 build 過 這些 專案, 更 可以 增加 工作 效率 (不用 incluir 相關 檔案 跟 link .a 或 拖拉 framework 到 專案 底下)
有時候 看看 別人 的 podfile 尋找 適合 自己 的 工具 也 很.

<! – mais ->

Instalação

$ sudo gem install cocoapods

官方 教學

Podfile

# Networking
pod
'AFNetworking', '~> 2.0'
# Model
# Debug
pod
"SPLogManager"
# UI
pod
'ECSlidingViewController', '~> 2.0.2'
# Testing

可以在自己的xcodeproj那層新增Podfile如上內容
使用

pod install

替 projeto xcode 做 設定 (就是 以前 拖拉 檔案 include 的 繁瑣 過程)
後面 也 可以 不 加上 版 號 在 使用pod update即 是
最新.

open App.xcworkspace

記得 要 開 workspace, 很多 人 一 開始 開始 會 還是 習慣 開 開 的 xcode project, 會 奇怪 為什麼 build 不過 找不到 相關 檔案
最後 記得 source control 的 時候 除了 Podfile, Podfile.lock 也要 記得 commit

Podspec

如果 Cocoapods 上 找不到 想要 的 pod
也 可以 自己 寫 自己 創造.

$ pod spec create Peanut

會 幫 projeto xcode 產生 一個 .podspec
內容 大致 如下 針對 每個 欄 位.

Pod::Spec.new do |s|
s
.name = "SPLogManager"
s
.version = "1.5"
s
.summary = "A simple log manager support file logger and dynamic log level setting."

s
.description = <<-DESC
SPLogManager is a simple class which manage CocoaLumberjack and NSLogger.
SPLogManager provide dynamic log level with type checking.
DESC


s
.homepage = "https://github.com/hsin919/NSLogger-CocoaLumberjack-connector"
s
.license = "BSD"
s
.author = { "hsin" => "hsin919@gmail.com" }
s
.social_media_url = "https://twitter.com/hsin919"

s
.ios.platform = :ios, '5.0'
s
.osx.platform = :osx, '10.7'
s
.source = { :git => "https://github.com/hsin919/NSLogger-CocoaLumberjack-connector.git", :tag => "1.5" }
s
.source_files = '*.{h,m}', 'SPLogManager/*.{h,m}'
s
.requires_arc = true
s
.dependency "CocoaLumberjack"
s
.dependency "NSLogger"
end

編輯 完後 可以 透過

$ pod spec lint Peanut.podspec

會 幫忙 檢查 相依 性 性 以及 erro / aviso, 沒 問題 的 話 就會 publicar 出去
網路 上 找到 很多 資料 會 告訴 你 透過 solicitação pull CocoaPods / Specs
做到 mesclar para cocoapods 的 方法 是 舊 的, solicitação pull 不會 成功 必須 透過.的 方法

Referência