[转载:http://www.cocoachina.com/ios/20171120/21234.html](http://www.cocoachina.com/ios/20171120/21234.html)
![image](//upload-images.jianshu.io/upload_images/3094887-9657f877b3986bab.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

> 做iOS开发的同学对这张图片再熟悉不过了,在使用第三库的时候,cocoapods确实给我们带来了极大的方便。那么,我们如何制作自己的pod呢?下面是之前的实践笔记

[参考资料 https://guides.cocoapods.org/](https://guides.cocoapods.org/)

[ShareUIDemo 链接](https://link.jianshu.com/?t=https://github.com/shiyeli/ShareUIDemo)

Demo中的组件式样:
![image](//upload-images.jianshu.io/upload_images/3094887-425680bf62686650.gif?imageMogr2/auto-orient/strip)

cocoapods文档提供了两种方法:

方法1 pod lib create YeshifuShareUI
方法2 pod spec create YeshifuShareUI
两种方法之前都尝试过,方法一会帮助你创建一大堆的文件,包括演示demo创建;方法二方便你在现有的项目中提取你需要制作pod的代码。
这里使用方法2。

详细步骤

1 整理代码

随便找一个现有的项目,把里面的一个模块放在同一个文件夹下,我这里放在ShareUI文件夹下面。

![image](//upload-images.jianshu.io/upload_images/3094887-8af3b6c0fb00cc44.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

图一 项目目录结构

2 创建 YeshifuShareUI.podspec文件

在终端cd 到ShareUIDemo (如图一所示),执行
`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组件化实践"
# 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 = < "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 = { "叶同学" => "yeli.studio@qq.com" }
# Or just: s.author = "叶同学"
# s.authors = { "叶同学" => "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为基准。
#如果你的YeshifuShareUI.podspec文件在其他层级处创建的,那么根据自己的情况写。
#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
```
对于其他配置,根据需要,删删改改依葫芦画瓢就好。

4 提交项目代码到github远程仓库

依次执行:

git add . && git commit -m'配置podspec'
git tag 0.0.5 && git push --tags

5 验证YeshifuShareUI.podspec 是否正确

pod lib lint

![image](//upload-images.jianshu.io/upload_images/3094887-05a02f3d0e8b1235.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

6 注册下CoocaPods ,终端执行`pod trunk register ymnlwyy@sina.com wandou`,之后你会收到一份邮件,点击邮件里面链接验证。

7 提交到CocoaPods

pod trunk push YeshifuShareUI.podspec
Success !

![image](//upload-images.jianshu.io/upload_images/3094887-f9e1c11be1675d09.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

完毕之后在CocoaPods搜索试试看

补充
遇到的问题:
* Could not find remote branch 0.0.1 to clone
```
warning: Could not find remote branch 0.0.1 to clone.
fatal: Remote branch 0.0.1 not found in upstream origin
```

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
我的博客 http://yeli.studio
[参考链接:http://www.jianshu.com/p/7e82f4f56b7e](http://www.jianshu.com/p/7e82f4f56b7e)

cocoa组件化开发的更多相关文章

  1. vue.js组件化开发实践

    前言 公司目前制作一个H5活动,特别是有一定统一结构的活动,都要码一个重复的轮子.后来接到一个基于模板的活动设计系统的需求,便有了下面的内容.借油开车. 组件化 需求一到,接就是怎么实现,技术选型自然 ...

  2. ReactNative新手学习之路04 组件化开发轮播图swiper支持安卓和IOS

    react native 新手之路04 组件化开发轮播图swiper支持安卓和IOS npm install react-native-carousel --save git 地址Properties ...

  3. Webpack+Vue+ES6 前端组件化开发mobile-multi-page应用实战总结

    本文版权归博客园和作者吴双本人共同所有 转载和爬虫请注明原文地址 www.cnblogs.com/tdws 一.写在前面 项目上线有一段时间了,一个基于webpack+vue+ES6的手机端多页面应用 ...

  4. Android组件化开发的简单应用

    组件化开发的主要步骤: 一.新建Modules 1.新建Project,作为应用的主Module. 2.新建Module:"Common",类型选择"Android Li ...

  5. 前端笔记之JavaScript面向对象(四)组件化开发&轮播图|俄罗斯方块实战

    一.组件化开发 1.1组件化概述 页面特效的制作,特别需要HTML.CSS有固定的布局,所以说现在越来越流行组件开发的模式,就是用JS写一个类,当你实例化这个类的时候,页面上的效果布局也能自动完成. ...

  6. vue(9)—— 组件化开发 - webpack(3)

    前面两个终于把webpack相关配置解析完了.现在终于进入vue的开发了 vue组件化开发预热 前期准备 创建如下项目: app.js: footer.js: main.js: webpack.con ...

  7. vue(8)—— 组件化开发 - webpack(2)

    webpack的常用loder和插件 loder和插件是什么,现在暂且不表,看到后面你就懂了 引入css问题 直接用link标签导入css 在前面的 vue(7)—— 组件化开发 — webpack( ...

  8. AppBoxFuture(六): 前端组件化开发

      前面几篇都是在介绍结构化与非结构化的数据存储,本篇换换口味介绍一下框架是如何实现前端组件化开发的.首先得感谢Vue.ElementUI等优秀的前端开源项目,这些项目帮助作者快速实现了框架的两个前端 ...

  9. 如何理解Unity组件化开发模式

    Unity的开发模式核心:节点和组件,组件可以加载到任何节点上,每个组件都有 gameobject 属性,可以通过这个属性获取到该节点,即游戏物体. 也就是说游戏物体由节点和组件构成,每个组件表示物体 ...

随机推荐

  1. IAR KEIL ECLIPSE使用JlinkScript文件进行调试

    转载自:https://wiki.segger.com/Using_J-Link_Script_Files Using J-Link Script Files     Contents [hide]  ...

  2. Linux mmc framework1:软件架构

    [部分内容来自] http://www.wowotech.net/comm/mmc_framework_arch.html 1. 前言 由eMMC基础技术1:MMC简介中MMC.SD.SDIO的介绍可 ...

  3. OA协同办公软件

    OA协同办公软件: 泛微软件. 九思软件. 华天动力. 万户OA.:北京万户网络技术有限公司创立于1998年2月,是北京华宇软件股份有限公司(股票简称:“华宇软件”,股票代码:300271)的全资子公 ...

  4. listener failed: zbx_tcp_listen() fatal error: unable to serve on any address [[-]:20050]

    故障现象: 客户端报错:service zabbix-agent 启动后,端口没有被正常监听,服务端也无法正常连接 将客户端改为二进制文件安装也不能正常启动/usr/local/zabbix/sbin ...

  5. spring boot 中的热部署

    <plugin>    <groupId>org.springframework.boot</groupId>    <artifactId>sprin ...

  6. 调试Windows Service

    调试Windows Service 使用一般的调试方法调试不了Windows Servers,所以参考了一些调试方法 我服务源码中使用了Timer,注意不能使用工具箱内的Timer,用System.T ...

  7. Ext.util.Format.date与Ext.Date.format区别, 转换时间戳

    在Extjs中装时间戳使用如下两种都可以: Ext.util.Format.date(time,'U'); Ext.Date.format(time, 'U'); 为了找到它们的区别,查看源代码,以E ...

  8. charles mock方法及问题

    一. 抓包后修改返回数据1.生成一个完成的请求返回信息1.charles抓取一个完整的请求,返回数据2.然后找到该请求,右键“save response”,将该完整请求返回文件保存至本地3.修改本地需 ...

  9. Spatial Transformer Networks

    参考:http://blog.csdn.net/xbinworld/article/details/69049680 论文的关键在理解这句话: 先通过V中坐标(xtarget,ytarget)以此找到 ...

  10. 在 laravel 的 DB::transaction 中,为外部变量赋值

    例如,我想在 laravel 的事务中,对某个外部变量赋值,然后在后续的逻辑中判断该变量的属性 $user = null; // init DB::transaction(function() use ...