iOS組件化實(shí)踐(基于CocoaPods)

做iOS開發(fā)的同學(xué)對這張圖片再熟悉不過了峭梳,在使用第三庫的時(shí)候葱椭,cocoapods確實(shí)給我們帶來了極大的方便。那么口四,我們?nèi)绾沃谱髯约旱膒od呢孵运?下面是之前的實(shí)踐筆記

參考資料 https://guides.cocoapods.org/
github 代碼
Demo中的組件式樣:

cocoapods文檔提供了兩種方法:

  • 方法1 pod lib create YeshifuShareUI
  • 方法2 pod spec create YeshifuShareUI
    兩種方法之前都嘗試過,方法一會幫助你創(chuàng)建一大堆的文件蔓彩,包括演示demo創(chuàng)建治笨;方法二方便你在現(xiàn)有的項(xiàng)目中提取你需要制作pod的代碼。
    這里使用方法2赤嚼。

在開始之前旷赖,我們先注冊下CoocaPods ,pod trunk register 422013052@qq.com yetongxue更卒,之后你會收到一份郵件,需要點(diǎn)下里面鏈接驗(yàn)證蹂空。

詳細(xì)步驟

1 整理代碼

隨便找一個(gè)現(xiàn)有的項(xiàng)目俯萌,把里面的一個(gè)模塊放在同一個(gè)文件夾下果录,我這里放在ShareUI文件夾下面。

圖一 項(xiàng)目目錄結(jié)構(gòu)

2 創(chuàng)建 YeshifuShareUI.podspec文件

在終端cd 到ShareUIDemo (如圖一所示)咐熙,執(zhí)行pod spec create YeshifuShareUI ,得到文件YeshifuShareUI.podspec

3 編輯 YeshifuShareUI.podspec
#
#  Be sure to run `pod spec lint YeshifuShareUI.podspec' to ensure this is a
#  valid spec and to remove all comments including this before submitting the spec.
#
#  To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
#  To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

  # ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  These will help people to find your library, and whilst it
  #  can feel like a chore to fill in it's definitely to your advantage. The
  #  summary should be tweet-length, and the description more in depth.
  #

  s.name         = "YeshifuShareUI"
  s.version      = "0.0.5"
  s.summary      = "CocoaPods組件化實(shí)踐"

  # This description is used to generate tags and improve search results.
  #   * Think: What does it do? Why did you write it? What is the focus?
  #   * Try to keep it short, snappy and to the point.
  #   * Write the description between the DESC delimiters below.
  #   * Finally, don't worry about the indent, CocoaPods strips it!
  s.description  = <<-DESC
  CocoaPods組件化實(shí)踐雕憔,一個(gè)簡簡單單的分享界面。
                   DESC

  s.homepage     = "https://github.com/shiyeli/ShareUIDemo"
  # s.screenshots  = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"


  # ―――  Spec License  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Licensing your code is important. See http://choosealicense.com for more info.
  #  CocoaPods will detect a license file if there is a named LICENSE*
  #  Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
  #

  s.license      = "MIT"
  # s.license      = { :type => "MIT", :file => "FILE_LICENSE" }


  # ――― Author Metadata  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the authors of the library, with email addresses. Email addresses
  #  of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
  #  accepts just a name if you'd rather not provide an email address.
  #
  #  Specify a social_media_url where others can refer to, for example a twitter
  #  profile URL.
  #

  s.author             = { "葉同學(xué)" => "yeli.studio@qq.com" }
  # Or just: s.author    = "葉同學(xué)"
  # s.authors            = { "葉同學(xué)" => "yeli.studio@qq.com" }
  s.social_media_url   = "http://yeli.studio"

  # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If this Pod runs only on iOS or OS X, then specify the platform and
  #  the deployment target. You can optionally include the target after the platform.
  #

  # s.platform     = :ios
  #s.platform     = :ios, "8.0"
  s.ios.deployment_target = '8.0'    #指定平臺和最低支持版本
  #  When using multiple platforms
  # s.ios.deployment_target = "5.0"
  # s.osx.deployment_target = "10.7"
  # s.watchos.deployment_target = "2.0"
  # s.tvos.deployment_target = "9.0"


  # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the location from where the source should be retrieved.
  #  Supports git, hg, bzr, svn and HTTP.
  #

  s.source       = { :git => "https://github.com/shiyeli/ShareUIDemo.git", :tag => "#{s.version}" }


  # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  CocoaPods is smart about how it includes source code. For source files
  #  giving a folder will include any swift, h, m, mm, c & cpp files.
  #  For header files it will include any header in the folder.
  #  Not including the public_header_files will make all headers public.
  #

  #這里路徑需要注意下糖声,是以YeshifuShareUI.podspec為基準(zhǔn)。
  #如果你的YeshifuShareUI.podspec文件在其他層級處創(chuàng)建的分瘦,那么根據(jù)自己的情況寫蘸泻。
  #ShareUI正是放置組件代碼的文件夾
  s.source_files  = "ShareUIDemo/ShareUIDemo/ShareUI", "ShareUI/**/*.{h,m}"  
  
  #s.exclude_files = "Classes/Exclude"

  # s.public_header_files = "Classes/**/*.h"


  # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  A list of resources included with the Pod. These are copied into the
  #  target bundle with a build phase script. Anything else will be cleaned.
  #  You can preserve files from being cleaned, please don't preserve
  #  non-essential files like tests, examples and documentation.
  #

  # s.resource  = "icon.png"
  # s.resources = "Resources/*.png"

  # s.preserve_paths = "FilesToSave", "MoreFilesToSave"


  # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Link your library with frameworks, or libraries. Libraries do not include
  #  the lib prefix of their name.
  #

  s.framework  = "UIKit"
  # s.frameworks = "SomeFramework", "AnotherFramework"

  # s.library   = "iconv"
  # s.libraries = "iconv", "xml2"


  # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If your library depends on compiler flags you can set them in the xcconfig hash
  #  where they will only apply to your library. If you depend on other Podspecs
  #  you can include multiple dependencies to ensure it works.

  s.requires_arc = true

  # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
  # s.dependency "JSONKit", "~> 1.4"

end

對于其他配置,根據(jù)需要嘲玫,刪刪改改依葫蘆畫瓢就好悦施。

4 提交項(xiàng)目代碼到github遠(yuǎn)程倉庫

依次執(zhí)行:

git add .  && git commit -m'配置podspec'
git tag 0.0.5 && git push --tags
5 驗(yàn)證YeshifuShareUI.podspec 是否正確

pod lib lint

6 提交到CocoaPods

pod trunk push YeshifuShareUI.podspec
Success !

完畢之后在CocoaPods搜索試試看


補(bǔ)充


Cocoapods 版本要求1.0.0 +
注冊之后修改用戶名:
grep -A2 'trunk.cocoapods.org' ~/.netrc

curl -v -H "Acdef6f817a3e4" -H "Content-Type: application/json" -X POST -d '{"email":"422013052@qq.com","name”:"newname","description":"iMac"}' https://trunk.cocoapods.org/api/v1/sessions

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市去团,隨后出現(xiàn)的幾起案子抡诞,更是在濱河造成了極大的恐慌,老刑警劉巖土陪,帶你破解...
    沈念sama閱讀 218,682評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件昼汗,死亡現(xiàn)場離奇詭異,居然都是意外死亡鬼雀,警方通過查閱死者的電腦和手機(jī)顷窒,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來源哩,“玉大人鞋吉,你說我怎么就攤上這事±常” “怎么了谓着?”我有些...
    開封第一講書人閱讀 165,083評論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長坛掠。 經(jīng)常有香客問我赊锚,道長,這世上最難降的妖魔是什么屉栓? 我笑而不...
    開封第一講書人閱讀 58,763評論 1 295
  • 正文 為了忘掉前任改抡,我火速辦了婚禮,結(jié)果婚禮上系瓢,老公的妹妹穿的比我還像新娘阿纤。我一直安慰自己,他們只是感情好夷陋,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,785評論 6 392
  • 文/花漫 我一把揭開白布欠拾。 她就那樣靜靜地躺著胰锌,像睡著了一般。 火紅的嫁衣襯著肌膚如雪藐窄。 梳的紋絲不亂的頭發(fā)上资昧,一...
    開封第一講書人閱讀 51,624評論 1 305
  • 那天,我揣著相機(jī)與錄音荆忍,去河邊找鬼格带。 笑死,一個(gè)胖子當(dāng)著我的面吹牛刹枉,可吹牛的內(nèi)容都是我干的叽唱。 我是一名探鬼主播,決...
    沈念sama閱讀 40,358評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼微宝,長吁一口氣:“原來是場噩夢啊……” “哼棺亭!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起蟋软,我...
    開封第一講書人閱讀 39,261評論 0 276
  • 序言:老撾萬榮一對情侶失蹤镶摘,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后岳守,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體凄敢,經(jīng)...
    沈念sama閱讀 45,722評論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年湿痢,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了贡未。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,030評論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡蒙袍,死狀恐怖俊卤,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情害幅,我是刑警寧澤消恍,帶...
    沈念sama閱讀 35,737評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站以现,受9級特大地震影響狠怨,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜邑遏,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,360評論 3 330
  • 文/蒙蒙 一佣赖、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧记盒,春花似錦憎蛤、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽萎胰。三九已至,卻和暖如春棚辽,著一層夾襖步出監(jiān)牢的瞬間技竟,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評論 1 270
  • 我被黑心中介騙來泰國打工屈藐, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留榔组,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,237評論 3 371
  • 正文 我出身青樓联逻,卻偏偏與公主長得像搓扯,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子遣妥,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,976評論 2 355

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

  • 做iOS開發(fā)的同學(xué)對這張圖片再熟悉不過了,在使用第三庫的時(shí)候攀细,cocoapods確實(shí)給我們帶來了極大的方便箫踩。那么,...
    軟件iOS開發(fā)閱讀 346評論 0 0
  • 項(xiàng)目組件化谭贪、平臺化是技術(shù)公司的共同目標(biāo)境钟,越來越多的技術(shù)公司推崇使用pod管理第三方庫以及私有組件,一方面使項(xiàng)目架構(gòu)...
    swu_luo閱讀 21,773評論 0 39
  • 一俭识、創(chuàng)建的github倉庫原文地址 1 進(jìn)入Github網(wǎng)站www.github.com登陸自己的賬號后 2 建立...
    freesan44閱讀 3,932評論 2 12
  • 最近在學(xué)習(xí)vue.js的時(shí)候發(fā)現(xiàn)慨削,vue的組件化的思想對于編寫代碼是一個(gè)非常有用的事情。 首先為什么需要組件化套媚? ...
    拂曉的云閱讀 7,172評論 6 23
  • 項(xiàng)目需求 1缚态、車牌+箱號識別系統(tǒng) 2、智能閘口系統(tǒng) 3堤瘤、IC卡玫芦、RFID卡制卡系統(tǒng) 4、電子關(guān)鎖識別系統(tǒng) 5本辐、閘口...
    gaoxw閱讀 285評論 0 0