CocoaPods學(xué)習(xí)02-PodSpec

CocoaPods學(xué)習(xí)01-Podfile
CocoaPods學(xué)習(xí)03-pod install vs pod update
CocoaPods學(xué)習(xí)04-制作自己的pod庫

.podspec文件猜年,相當(dāng)于pod庫的一個(gè)映射描述文件

根屬性

  • name庫名 spec.name = 'AFNetworking'

  • version版本號(hào) spec.version = '3.0.0'

  • authors作者 單人或者多人

    spec.author = 'ZJ' 
    spec.authors = 'AZJ','BZJ'  
    spec.authors = { 'AZJ' => 'azj@google.com',
    'BZJ' = > 'bzj@sina.cn'}
    
  • license 版權(quán)許可 spec.license = 'MIT'

  • homepage 主頁 spec.homepage = 'http://www.zj.github.io'

  • source 庫源地址
    git 指定tag
    spec.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => spec.version.to_s }
    svn 指定tag
    spec.source = { :svn => 'http://svn.code.sf.net/p/polyclipping/code', :tag => '4.8.8' }
    http地址 支持的格式有zip, tgz, bz2, txz 和 tar
    指定hash碼 支持sha1和sha256
    spec.source = { :http => 'http://dev.wechatapp.com/download/sdk/WeChat_SDK_iOS_en.zip' :sha1 => '7e21857fe11a511f472cfd7cfa2d979bd7ab7d96'}

  • summary 摘要
    spec.summary = 'How to make love!'

以上都是必須設(shè)置的 ,下面的為可選

  • cocoapods_version支持的CocoaPods版本號(hào) spec.cocoapods_version = '>= 0.36'
  • description描述
spec.description = <<-DESC
                     Computes the meaning of life.
                     Features:
                     1. Is self aware
                     ...
                     42. Likes candies.
                   DESC
  • screenshots 快照
spec.screenshot = [ 'http://dl.dropbox.com/u/378729/MBProgressHUD/1.png',
                     'http://dl.dropbox.com/u/378729/MBProgressHUD/2.png' ]`
  • documentation_url 文檔地址
    spec.documentation_url = 'http://www.example.com/docs.html'

  • requires_arc 是否需要arc環(huán)境
    spec.requires_arc = true

  • deprecated 棄用
    spec.deprecated = true

平臺(tái)

設(shè)置支持的平臺(tái)及版本號(hào)

spec.platform = :osx, '10.8'
spec.platform = :ios
spec.platform = :osx

spec.ios.deployment_target = '6.0'
spec.osx.deployment_target = '10.8'

編譯設(shè)置

  • dependency 依賴的其他庫
    spec.dependency 'AFNetworking', '~> 1.0'
    spec.ios.dependency 'MBProgressHUD', '~> 0.5'

  • frameworks 依賴的framework
    spec.ios.framework = 'CFNetwork'
    spec.frameworks = 'QuartzCore', 'CoreData'

  • libraries 依賴的libraries
    spe.ios.library = 'xml2'
    spe.libraries = 'xml2', 'z'

  • compiler_flags 編譯設(shè)置(如警告忽略疆瑰,宏設(shè)置)
    spec.compiler_flags = '-Wno-format', '-DOS_OBJECT_USE_OBJC=0'

  • prefix_header_contents pch預(yù)編譯頭文件內(nèi)容
    spec.prefix_header_contents = '#import <UIKit/UIKit.h>'

  • prefix_header_file pch預(yù)編譯頭文件路徑
    spec.prefix_header_file = 'iphone/include/prefix.pch'

文件樣式

Podspecs應(yīng)該放在repository的根目錄
*匹配所有企巢,?匹配一個(gè)任意字符辰斋,[^a-d]匹配集合內(nèi)字符 {p,q}匹配p或q \跳過下一個(gè)

"JSONKit.?" 所有的jsonkit為名的文件
"*" 所有文件
"*.{h,m}" 所有的.h.m文件
  • source_files 源文件
    spec.source_files = 'Classes/**/*.{h,m}'
    spec.source_files = 'Classes/**/*.{h,m}', 'More_Classes/**/*.{h,m}'

  • public_header_files 公開頭文件 用戶可以引入查看的頭文件 ,不設(shè)置則搜有的頭文件都可以引入
    spec.public_header_files = 'Headers/Public/*.h'

  • private_header_files 私有頭文件 用戶不可以引入的頭文件
    spec.private_header_files = 'Headers/Private/*.h'

  • resource_bundles 資源包 推薦使用

spec.resource_bundles = {
   'MapBox' => ['MapView/Map/Resources/*.png'],
   'OtherResources' => ['MapView/Map/OtherResources/*.png']
 }
  • resources 資源包
    spec.resource = 'MJRefresh/MJRefresh.bundle'

  • subspec 子模塊依賴

實(shí)用示例

MJRefresh的spec

Pod::Spec.new do |s|
    s.name         = 'MJRefresh'
    s.version      = '3.1.15.1'
    s.summary      = 'An easy way to use pull-to-refresh'
    s.homepage     = 'https://github.com/CoderMJLee/MJRefresh'
    s.license      = 'MIT'
    s.authors      = {'MJ Lee' => 'richermj123go@vip.qq.com'}
    s.platform     = :ios, '6.0'
    s.source       = {:git => 'https://github.com/CoderMJLee/MJRefresh.git', :tag => s.version}
    s.source_files = 'MJRefresh/**/*.{h,m}'
    s.resource     = 'MJRefresh/MJRefresh.bundle'
    s.requires_arc = true
end

SDWebImage的spec

Pod::Spec.new do |s|
  s.name = 'SDWebImage'
  s.version = '4.2.2'

  s.osx.deployment_target = '10.8'
  s.ios.deployment_target = '7.0'
  s.tvos.deployment_target = '9.0'
  s.watchos.deployment_target = '2.0'

  s.license = 'MIT'
  s.summary = 'Asynchronous image downloader with cache support with an UIImageView category.'
  s.homepage = 'https://github.com/rs/SDWebImage'
  s.author = { 'Olivier Poitrey' => 'rs@dailymotion.com' }
  s.source = { :git => 'https://github.com/rs/SDWebImage.git', :tag => s.version.to_s }

  s.description = 'This library provides a category for UIImageView with support for remote '      \
                  'images coming from the web. It provides an UIImageView category adding web '    \
                  'image and cache management to the Cocoa Touch framework, an asynchronous '      \
                  'image downloader, an asynchronous memory + disk image caching with automatic '  \
                  'cache expiration handling, a guarantee that the same URL won\'t be downloaded ' \
                  'several times, a guarantee that bogus URLs won\'t be retried again and again, ' \
                  'and performances!'

  s.requires_arc = true
  s.framework = 'ImageIO'
  
  s.default_subspec = 'Core'

  s.subspec 'Core' do |core|
    core.source_files = 'SDWebImage/{NS,SD,UI}*.{h,m}'
    core.exclude_files = 'SDWebImage/UIImage+WebP.{h,m}', 'SDWebImage/SDWebImageWebPCoder.{h,m}'
    core.tvos.exclude_files = 'SDWebImage/MKAnnotationView+WebCache.*'
  end

  s.subspec 'MapKit' do |mk|
    mk.osx.deployment_target = '10.8'
    mk.ios.deployment_target = '7.0'
    mk.tvos.deployment_target = '9.0'
    mk.source_files = 'SDWebImage/MKAnnotationView+WebCache.*'
    mk.framework = 'MapKit'
    mk.dependency 'SDWebImage/Core'
  end

  s.subspec 'GIF' do |gif|
    gif.ios.deployment_target = '7.0'
    gif.source_files = 'SDWebImage/FLAnimatedImage/*.{h,m}'
    gif.dependency 'SDWebImage/Core'
    gif.dependency 'FLAnimatedImage', '~> 1.0'
    gif.xcconfig = {
      'USER_HEADER_SEARCH_PATHS' => '$(inherited) $(SRCROOT)/FLAnimatedImage/FLAnimatedImage'
    }
  end

  s.subspec 'WebP' do |webp|
    webp.source_files = 'SDWebImage/UIImage+WebP.{h,m}', 'SDWebImage/SDWebImageWebPCoder.{h,m}'
    webp.xcconfig = { 
      'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) SD_WEBP=1',
      'USER_HEADER_SEARCH_PATHS' => '$(inherited) $(SRCROOT)/libwebp/src'
    }
    webp.watchos.xcconfig = {
      'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) SD_WEBP=1 WEBP_USE_INTRINSICS=1',
      'USER_HEADER_SEARCH_PATHS' => '$(inherited) $(SRCROOT)/libwebp/src'
    }
    webp.dependency 'SDWebImage/Core'
    webp.dependency 'libwebp'
  end
end

參考地址
cocoapods guides

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市们镜,隨后出現(xiàn)的幾起案子硝逢,更是在濱河造成了極大的恐慌姨拥,老刑警劉巖绅喉,帶你破解...
    沈念sama閱讀 217,509評(píng)論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異叫乌,居然都是意外死亡柴罐,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門憨奸,熙熙樓的掌柜王于貴愁眉苦臉地迎上來革屠,“玉大人,你說我怎么就攤上這事排宰∷浦ィ” “怎么了?”我有些...
    開封第一講書人閱讀 163,875評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵板甘,是天一觀的道長党瓮。 經(jīng)常有香客問我,道長盐类,這世上最難降的妖魔是什么寞奸? 我笑而不...
    開封第一講書人閱讀 58,441評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮在跳,結(jié)果婚禮上枪萄,老公的妹妹穿的比我還像新娘。我一直安慰自己猫妙,他們只是感情好瓷翻,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,488評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著吐咳,像睡著了一般逻悠。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上韭脊,一...
    開封第一講書人閱讀 51,365評(píng)論 1 302
  • 那天童谒,我揣著相機(jī)與錄音,去河邊找鬼沪羔。 笑死饥伊,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的蔫饰。 我是一名探鬼主播琅豆,決...
    沈念sama閱讀 40,190評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼篓吁!你這毒婦竟也來了茫因?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,062評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤杖剪,失蹤者是張志新(化名)和其女友劉穎冻押,沒想到半個(gè)月后驰贷,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,500評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡洛巢,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,706評(píng)論 3 335
  • 正文 我和宋清朗相戀三年括袒,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片稿茉。...
    茶點(diǎn)故事閱讀 39,834評(píng)論 1 347
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡锹锰,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出漓库,到底是詐尸還是另有隱情恃慧,我是刑警寧澤,帶...
    沈念sama閱讀 35,559評(píng)論 5 345
  • 正文 年R本政府宣布米苹,位于F島的核電站糕伐,受9級(jí)特大地震影響砰琢,放射性物質(zhì)發(fā)生泄漏蘸嘶。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,167評(píng)論 3 328
  • 文/蒙蒙 一陪汽、第九天 我趴在偏房一處隱蔽的房頂上張望训唱。 院中可真熱鬧,春花似錦挚冤、人聲如沸况增。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽澳骤。三九已至,卻和暖如春澜薄,著一層夾襖步出監(jiān)牢的瞬間为肮,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評(píng)論 1 269
  • 我被黑心中介騙來泰國打工肤京, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留颊艳,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,958評(píng)論 2 370
  • 正文 我出身青樓忘分,卻偏偏與公主長得像棋枕,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子妒峦,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,779評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容