[转载: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. oracle 行号和分页

    1.行号是个伪列,rownum 永远按照默认的顺序生成 2.rownum 只能使用< <= 不能使用>  >=(原因是oracle数据库是行式数据库,像盖楼一样,没有第一层就排 ...

  2. Python基础-封装与扩展、静态方法和类方法

    一.封装与扩展 封装在于明确区分内外,使得类实现者可以修改封装内的东西而不影响外部调用者的代码:而外部使用者只知道一个接口(函数),只要接口(函数)名.参数不变,使用者的代码永远无需改变.这就提供一个 ...

  3. Linux Kernel 代码艺术——编译时断言【转】

    转自:http://www.cnblogs.com/hazir/p/static_assert_macro.html 本系列文章主要写我在阅读Linux内核过程中,关注的比较难以理解但又设计巧妙的代码 ...

  4. Git学习笔记一《版本控制之道-使用Git》

    1.在Windows中安装完git后,需要进行一下配置:$ git config --global user.name "zhangliang"$ git config --glo ...

  5. 第一个Spring Boot程序

    Windows 10家庭中文版,java version "1.8.0_152", Eclipse Oxygen.1a Release (4.7.1a),Spring Tools ...

  6. 微服务(Microservices )简介

    概念 微服务架构风格是一种将单个应用程序作为一套小型服务开发的方法,每种应用程序都在自己的进程中运行, 并与轻量级机制(通常是HTTP资源API)进行通信. 这些服务是围绕业务功能构建的,可以通过全自 ...

  7. EntityFramework codefirst Enable-Migrations No context type was found in the assembly “MyApp.Web” error

    Enable-Migrations -Force -ContextTypeName "MyApp.Repository.DataContext" -ProjectName &quo ...

  8. OCM_第六天课程:Section3 —》数据库可用性

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  9. 【ES】match_phrase与regexp

    刚开始接触es,由于弄不清楚match_phrase和regexp导致很多查询结果与预想的不同.在这整理一下. regexp:针对的是单个词项 match_phrase:针对的是多个词项的相对位置 它 ...

  10. PHP实现字符串转义和还原

    首先大家可以简单了解下什么是转义字符?有什么用? 转义字符是一种特殊的字符常量.转义字符以反斜线"\"开头,后跟一个或几个字符.转义字符具有特定的含义,不同于字符原有的意义,故称“ ...