·
·
文章目录
  1. 写在前面
  2. 原因
  3. YFStartView
  4. 使用Cocoapods
  5. 参考

自定义库封装思路和Cocoapods发布

写在前面

近期自己封装了iOS客户端启动页的自定义库,在封装的过程中学习了很多,包括封装的思想以及Cocoapods发布。

原因

首先是因为千篇一律的使用图片进行启动页,在用户体验上确实引起了审美疲劳,然后是收到了Coding的启发,于是准备进行启动页的封装。

PS:不会设计的程序员不是好程序员!

YFStartView

目前YFStartView已经开源,效果图如下。

效果图1

效果图2

几点说明:

  • 尽量不要使用三方库(后来发现Cocoapods中有的库是可以的,因为发布到Cocoapods可以添加依赖,那么就不存在问题),因为手动添加了三方库,可能导致重复添加。

  • 尽可能的暴露出属性,让用户去选择使用的属性。

使用Cocoapods

初始化一个Podspec文件

1
pod spec create YFStartView

要像github仓库中添加.podspec文件,代码内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#
# Be sure to run `pod spec lint YFStartView.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 = "YFStartView"
s.version = "0.0.1"
s.summary = "YFStartView is an custom view for start image."

s.homepage = "https://github.com/yeziahehe/YFStartView"
# 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 = { "Ivan" => "yeziahehe@gmail.com" }
# Or just: s.author = "Ivan"
# s.authors = { "Ivan" => "yeziahehe@gmail.com" }
# s.social_media_url = "http://twitter.com/Ivan"

# ――― 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"

# When using multiple platforms
# s.ios.deployment_target = "5.0"
# s.osx.deployment_target = "10.7"
# s.watchos.deployment_target = "2.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/yeziahehe/YFStartView.git", :tag => "0.0.1" }


# ――― 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.
#

s.source_files = "YFStartView/*.{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 = "YFStartViewDemo"


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

# s.framework = "SomeFramework"
# 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
``

接着要注意版本号的问题

```bash
git tag -a 0.0.1 -m "Tag release 0.0.1"
git push —tags
git add YFStartView.podspec
git commit -m "add YFStartView.podspec file"
git push origin master

接下来很多教程里面写的fork,目前的话Cocoapods已经不支持pull request,改为trunk服务。

Cocoapods

更新了用trunk之后,CocoaPods 需要0.33版本以上的,用 pod –version 查看,如果版本低,需要更新。

1
pod trunk register yeziahehe@gmail.com 'yeziahehe'  --verbose

接下来会收到一封邮件进行验证。

1
pod trunk me

会显示如下信息。

1
2
3
4
5
6
- Name:     yeziahehe
- Email: yeziahehe@gmail.com
- Since: October 21st, 02:55
- Pods: None
- Sessions:
- October 21st, 02:55 - February 26th, 2016 02:57. IP:202.195.129.246

接下来进行提交

1
pod trunk push YFStartView.podspec

大功告成,搜索一下

1
pod search YFStartView

已经发布成功!

1
2
3
4
5
6
-> YFStartView (0.0.1)
YFStartView is an custom view for start image.
pod 'YFStartView', '~> 0.0.1'
- Homepage: https://github.com/yeziahehe/YFStartView
- Source: https://github.com/yeziahehe/YFStartView.git
- Versions: 0.0.1 [master repo]

参考

配置自己的CocoaPods库

CocoaPods 手把手五分钟教你制作自己的podspec文件

iOS:手把手教你发布代码到CocoaPods(Trunk方式)

**版权声明**

Ivan’s Blog by Ivan Ye is licensed under a Creative Commons BY-NC-ND 4.0 International License.
叶帆创作并维护的叶帆的博客博客采用创作共用保留署名-非商业-禁止演绎4.0国际许可证

本文首发于Ivan’s Blog | 叶帆的博客博客( http://yeziahehe.com ),版权所有,侵权必究。

本文链接:http://yeziahehe.com/2015/10/22/own_framework_and_Cocoapods_release/

支持一下
扫一扫,支持yeziahehe
  • 微信扫一扫
  • 支付宝扫一扫