SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler offline
做自己的可可豆夾
Objective-C 套件管理系統
cocoaheads.tw 2014
@Superbil
About me
•

軟體工工程師、iOS 開發

•

Git / Emacs

•

about.me/superbil

•

freenode #emacs.tw #g0v.tw #python.tw
目錄
•

什麼是 cocoapods

•

建立一個 podspec

•

建立屬於自己的私人 repo

•

編寫 podspec 的注意事項

•

Podspec 裡面的奇技

巧
什麼是 cocoapods
•

語意化版本 (Semantic Versioning) 套件管理系統

•

快速(

•

解決套件之間的相依性問題

懶)使用第三方元件
為什麼要用 cocoapods
•

語意化版本 (Semantic Versioning) 套件管理系統
•

•

快速(
•

•

多人協作的時候,知道該不該升級元件
懶)使用第三方元件

pod search <Make_a_wish>

解決套件之間的相依性問題
•

duplicate symbols
使用 cocoapods
•

gem install cocoapods
•

•

建議先裝 homebrew,再裝ruby

pod setup
•

安裝完,設定 cocoapods 環境
使用 cocoapods (2)
•

pod init
•

在當前目錄下面尋找 xcode project ,

並建立一個 Podfile

•

pod install
•

依照 Podfile 中的需求,安裝到 xcode project
使用 cocoapods (3)
•

platform :ios, '5.1'

•

xcodeproj `MyProject.xcodeproj`

•

pod 'JSONKit',

•

pod 'Reachability', '~> 3.0.0'

'~> 1.4'
更新 Pod
•

pod
•

•

依照目前(Podfile.lock)的 Pod 更新

pod update
•

更新 Podfile 中的 Pods
建立一個 podspec
•

podspec 表示一個單位

•

pod spec create <NAME>
•

只建立 podspec

,其他流程都要動手做
podspec Example
自己做 Pod 流程
•

建立 pod spec create <NAME>

•

增加 source code, example

•

上傳 source code 並加上 git tag

•

編寫 <NAME>.podspec

•

驗證 pod spec lint <NAME>.podspec

•

上傳 pod push origin <NAME>.podspec
每一個 podspec 都要
樣做一次...

是一個需要耐心的過程
pod lib create
•

使用 pod lib create <NAME>
•

clone_template
•

•

git clone pod-template <NAME>

configure_template
•

ruby! "_CONFIGURE.rb <NAME>
pod-template
•
•

Assets
CHANGELOG.md

•

NAME.podspec

•

POD_README.md

•

•

Project

Classes

•

•
•
•

ios
osx

LICENSE

Podfile

•

README.md

•

Rakefile

•

_CONFIGURE.rb
pod lib 開發流程
•

pod lib create <NAME>

•

add source code and edit <NAME>.podspec

•

pod lib lint

•

pod push origin <NAME>.podspec
建立自己的可可豆夾
pod repo 結構

•

$HOME/repos/master/ps_name/version/
ps_name.podspec

•

repo 使用 git 做管理
pod repo add
•

pod repo add NAME URL [BRANCH]
•

Clones `URL` in the local spec-repos directory at
`~/.cocoapods/repos/`. The

•

remote can later be referred to by `NAME`.
編寫 Podspec 的

注意事項
語意化版本 (1)
•

pod 'JSONKit', '~> 1.4'
•

•

•

可以使用不同的限制條件
會自動安裝 1.x 版的升級

pod 'JSONKit', '~> 1.4.1'
•

自動升級只到 1.4.x
語意化版本 (2)
•

主版號.次版號.修訂號
•

主版號:當你做了不相容的 API 修改

•

次版號:當你做了向下相容的功能性新增

•

修訂號:當你做了向下相容的問題修正
pod lint 錯誤 (1)

•

WARN | Git sources should specify a tag
•

podspec 的 source 必需指到一個 tag
pod lint 錯誤 (2)

•

WARN | The summary should end with proper
punctuation.
•

summary 少了句號。
pod lint 錯誤 (3)
•

pod lib lint 的檢查和 

pod push origin <NAME>.podpsec 範圍不同
•

雖然 pod lib lint 雖然可以過,但是上傳的時候才
會出現錯誤
先別說cocoapods
你知道相依性 ?
相依性處理
•

盡可以把沒有相依性的元件先
整理出來

•

先把影嚮最小的做成一個 pod

•

subspec 裡面可以做一些簡單
的相依性處理

•

用 Category 去處理相依性
Podspec 裡面的

奇技

巧
spec.xcconfig
•

s.xcconfig = { 'HEADER_SEARCH_PATHS' => '"$
(SDKROOT)/usr/include/libxml2"' }
•

在 Target 的 project 的
HEADER_SEARCH_PATHS 加上參數
•

HEADER_SEARCH_PATHS 為
MyProject.pbxproj 中的值,非介面上顯示的
spec.xcconfig

•

s.xcconfig = { 'OTHER_LDFLAGS' => '-ObjC' }
•

手動加入 -ObjC 的 flags
other link options

•

s.libraries = 'xml2'
•

會在 other link flags 加上 -llibxml2
spec.compiler_flags
•

s.compiler_flags = '-DGDATA_IPHONE=1', 'DGTM_INCLUDE_OAUTH2=1'
•

在 target project 中 compiler flags 加入自定義的
參數
subspec

•

pod 'MyPodspec/Common'
•

只要安裝

個 subspec 的方式
spec.default

•

pod 'MyPodspec'
•

預設會安裝的東西,會先安裝 spec 下的再
default_subspec 的東西
resource 的相依性
•

Pods-Target-resources.sh
•

•

•

把 resource 複製到 Project 上
使用 subspec 來整理 resource

spec.resource_bundles
spec.source
•

spec.version 若是 0.0.1
•

使用 0.0.1, 使用

個 version, source 可以使

用 :commit => "ABCDEFG.yooooooo"
•

s.source = { 

:git => 'git://repo.git', 

:commit => 'git_commit_hash'

}

http://guides.cocoapods.org/syntax/podspec.html#source
s.version 相容

•

GData 已經有新版本,但是最新的程式碼在 trunk 上
•

建立特別的版號,然後把 podspec 放在自己的 repo 中

•

pod 'GData', '~> 0.0.1-pp'
spec.post_install
•

在元件安裝完之後,要做一些

事情時

•

def s.post_install(target)

puts <<-TEXT

// mom, I am here !

TEXT

end

•

find ~/.cocoapods/repos/ -type f -exec grep -nH e "post_install" {} +
Ref
•

http://cocoapods.org/

•

http://guides.cocoapods.org/syntax/podspec.html

•

https://github.com/CocoaPods/CocoaPods

•

https://github.com/CocoaPods/pod-template

Mais conteúdo relacionado

Mais procurados

How to choose web framework
How to choose web frameworkHow to choose web framework
How to choose web frameworkBo-Yi Wu
 
Mercurial簡介與教學
Mercurial簡介與教學Mercurial簡介與教學
Mercurial簡介與教學芳本 林
 
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹Shengyou Fan
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upWen-Tien Chang
 
美团点评技术沙龙06 - 滴滴移动端测试解耦工具实践
美团点评技术沙龙06 - 滴滴移动端测试解耦工具实践美团点评技术沙龙06 - 滴滴移动端测试解耦工具实践
美团点评技术沙龙06 - 滴滴移动端测试解耦工具实践美团点评技术团队
 
Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Shengyou Fan
 
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊Shengyou Fan
 
Github简介及实用入门
Github简介及实用入门Github简介及实用入门
Github简介及实用入门Rongxing Liu
 
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發俊仁 陳
 
Java Build Tool course in 2011
Java Build Tool course in 2011Java Build Tool course in 2011
Java Build Tool course in 2011Ching Yi Chan
 
使用 wagon + VS Code 輕鬆打造 Windows 平台 PHP/Laravel 開發環境
使用 wagon + VS Code 輕鬆打造 Windows 平台 PHP/Laravel 開發環境使用 wagon + VS Code 輕鬆打造 Windows 平台 PHP/Laravel 開發環境
使用 wagon + VS Code 輕鬆打造 Windows 平台 PHP/Laravel 開發環境Shengyou Fan
 
導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事Weizhong Yang
 
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者Shengyou Fan
 
給 iOS 工程師的 Flutter 開發
給 iOS 工程師的 Flutter 開發給 iOS 工程師的 Flutter 開發
給 iOS 工程師的 Flutter 開發Weizhong Yang
 
Extend the Kubernetes API with CRD and Custom API Server
Extend the Kubernetes API with CRD and Custom API ServerExtend the Kubernetes API with CRD and Custom API Server
Extend the Kubernetes API with CRD and Custom API Serverinwin stack
 
Git and Github basic with SourceTree
Git and Github basic with SourceTreeGit and Github basic with SourceTree
Git and Github basic with SourceTreeChu-Siang Lai
 
Beta testing with CI
Beta testing with CIBeta testing with CI
Beta testing with CILiyao Chen
 

Mais procurados (20)

How to choose web framework
How to choose web frameworkHow to choose web framework
How to choose web framework
 
Mercurial簡介與教學
Mercurial簡介與教學Mercurial簡介與教學
Mercurial簡介與教學
 
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹
COSCUP 2016 Laravel 部署工作坊 - 生態圈介紹
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom up
 
美团点评技术沙龙06 - 滴滴移动端测试解耦工具实践
美团点评技术沙龙06 - 滴滴移动端测试解耦工具实践美团点评技术沙龙06 - 滴滴移动端测试解耦工具实践
美团点评技术沙龙06 - 滴滴移动端测试解耦工具实践
 
Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南
 
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊
[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊
 
課程簡介
課程簡介課程簡介
課程簡介
 
Github简介及实用入门
Github简介及实用入门Github简介及实用入门
Github简介及实用入门
 
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
LaravelConf Taiwan 2017 單頁面應用與前後端分離開發
 
驗證與訊息
驗證與訊息驗證與訊息
驗證與訊息
 
Java Build Tool course in 2011
Java Build Tool course in 2011Java Build Tool course in 2011
Java Build Tool course in 2011
 
使用 wagon + VS Code 輕鬆打造 Windows 平台 PHP/Laravel 開發環境
使用 wagon + VS Code 輕鬆打造 Windows 平台 PHP/Laravel 開發環境使用 wagon + VS Code 輕鬆打造 Windows 平台 PHP/Laravel 開發環境
使用 wagon + VS Code 輕鬆打造 Windows 平台 PHP/Laravel 開發環境
 
導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事
 
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
 
給 iOS 工程師的 Flutter 開發
給 iOS 工程師的 Flutter 開發給 iOS 工程師的 Flutter 開發
給 iOS 工程師的 Flutter 開發
 
Extend the Kubernetes API with CRD and Custom API Server
Extend the Kubernetes API with CRD and Custom API ServerExtend the Kubernetes API with CRD and Custom API Server
Extend the Kubernetes API with CRD and Custom API Server
 
Git and Github basic with SourceTree
Git and Github basic with SourceTreeGit and Github basic with SourceTree
Git and Github basic with SourceTree
 
Beta testing with CI
Beta testing with CIBeta testing with CI
Beta testing with CI
 
使用 Controller
使用 Controller使用 Controller
使用 Controller
 

Semelhante a 做自己的可可豆夾 @ cocoahead.tw

Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeAngel Boy
 
合久必分,分久必合
合久必分,分久必合合久必分,分久必合
合久必分,分久必合Qiangning Hong
 
GitLab—the new workbench
GitLab—the new workbenchGitLab—the new workbench
GitLab—the new workbenchtblanlan
 
Gitlab - the new workbench (2nd edition)
Gitlab - the new workbench (2nd edition)Gitlab - the new workbench (2nd edition)
Gitlab - the new workbench (2nd edition)Pu Shiming
 
愛創小小聚201307 小強分享
愛創小小聚201307 小強分享愛創小小聚201307 小強分享
愛創小小聚201307 小強分享iTrEnD
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛Edward Kuo
 
Nodejs & NAE
Nodejs & NAENodejs & NAE
Nodejs & NAEq3boy
 
DEV305 - ASP.NET 5 開發攻略
DEV305 - ASP.NET 5 開發攻略DEV305 - ASP.NET 5 開發攻略
DEV305 - ASP.NET 5 開發攻略Will Huang
 
開放原始碼 Ch2.1 app - oss - oss ide (ver1.2)
開放原始碼 Ch2.1   app - oss - oss ide (ver1.2)開放原始碼 Ch2.1   app - oss - oss ide (ver1.2)
開放原始碼 Ch2.1 app - oss - oss ide (ver1.2)My own sweet home!
 
NODEjs Lesson1
NODEjs Lesson1NODEjs Lesson1
NODEjs Lesson13dmodeldiy
 
千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7Justin Lin
 
⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨Wen-Tien Chang
 
[3]投影片 futurewad樹莓派研習會 141204
[3]投影片 futurewad樹莓派研習會 141204[3]投影片 futurewad樹莓派研習會 141204
[3]投影片 futurewad樹莓派研習會 141204CAVEDU Education
 
出了问题不要靠猜
出了问题不要靠猜出了问题不要靠猜
出了问题不要靠猜LI Daobing
 
Artifacts management with CI and CD
Artifacts management with CI and CDArtifacts management with CI and CD
Artifacts management with CI and CDChen-Tien Tsai
 
Software Engineer Talk
Software Engineer TalkSoftware Engineer Talk
Software Engineer TalkLarry Cai
 
Phalcon the fastest php framework 阿土伯
Phalcon   the fastest php framework 阿土伯Phalcon   the fastest php framework 阿土伯
Phalcon the fastest php framework 阿土伯Hash Lin
 
Phalcon phpconftw2012
Phalcon phpconftw2012Phalcon phpconftw2012
Phalcon phpconftw2012Rack Lin
 
SQL Server 資料庫版本控管
SQL Server 資料庫版本控管SQL Server 資料庫版本控管
SQL Server 資料庫版本控管Will Huang
 
Git&Github Tutorial
Git&Github TutorialGit&Github Tutorial
Git&Github TutorialTing Wen Su
 

Semelhante a 做自己的可可豆夾 @ cocoahead.tw (20)

Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
 
合久必分,分久必合
合久必分,分久必合合久必分,分久必合
合久必分,分久必合
 
GitLab—the new workbench
GitLab—the new workbenchGitLab—the new workbench
GitLab—the new workbench
 
Gitlab - the new workbench (2nd edition)
Gitlab - the new workbench (2nd edition)Gitlab - the new workbench (2nd edition)
Gitlab - the new workbench (2nd edition)
 
愛創小小聚201307 小強分享
愛創小小聚201307 小強分享愛創小小聚201307 小強分享
愛創小小聚201307 小強分享
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
 
Nodejs & NAE
Nodejs & NAENodejs & NAE
Nodejs & NAE
 
DEV305 - ASP.NET 5 開發攻略
DEV305 - ASP.NET 5 開發攻略DEV305 - ASP.NET 5 開發攻略
DEV305 - ASP.NET 5 開發攻略
 
開放原始碼 Ch2.1 app - oss - oss ide (ver1.2)
開放原始碼 Ch2.1   app - oss - oss ide (ver1.2)開放原始碼 Ch2.1   app - oss - oss ide (ver1.2)
開放原始碼 Ch2.1 app - oss - oss ide (ver1.2)
 
NODEjs Lesson1
NODEjs Lesson1NODEjs Lesson1
NODEjs Lesson1
 
千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7
 
⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨
 
[3]投影片 futurewad樹莓派研習會 141204
[3]投影片 futurewad樹莓派研習會 141204[3]投影片 futurewad樹莓派研習會 141204
[3]投影片 futurewad樹莓派研習會 141204
 
出了问题不要靠猜
出了问题不要靠猜出了问题不要靠猜
出了问题不要靠猜
 
Artifacts management with CI and CD
Artifacts management with CI and CDArtifacts management with CI and CD
Artifacts management with CI and CD
 
Software Engineer Talk
Software Engineer TalkSoftware Engineer Talk
Software Engineer Talk
 
Phalcon the fastest php framework 阿土伯
Phalcon   the fastest php framework 阿土伯Phalcon   the fastest php framework 阿土伯
Phalcon the fastest php framework 阿土伯
 
Phalcon phpconftw2012
Phalcon phpconftw2012Phalcon phpconftw2012
Phalcon phpconftw2012
 
SQL Server 資料庫版本控管
SQL Server 資料庫版本控管SQL Server 資料庫版本控管
SQL Server 資料庫版本控管
 
Git&Github Tutorial
Git&Github TutorialGit&Github Tutorial
Git&Github Tutorial
 

做自己的可可豆夾 @ cocoahead.tw