组件化学习
2017-03-22 本文已影响50人
马戏团小丑
-
组件化是什么
-
组件化是通过cocoapods的形式安装各个组件,那么就要了解cocoapods是怎么打造本地私有库,远程私有库
-
而组件化所需要的就是打造远程私有库
当pod install 远程私有库失败找不到的时候,项目工程中profile文件欠缺了远程私有库的源地址
source 'git@git.coding.net:seemygo_wangshunzi/XMGFMSpecs.git' // 远程私有库的源地址
source 'https://github.com/CocoaPods/Specs.git' // 远程公有库的源地址
在2.3提交代码到远程私有仓库后要修改.podspec文件才能2.5绑定tag,以下是.podspec修改后的样式,就是为了给本地私有仓库添加tag,再添加到远程(就是为了给远程绑定tag)
#
# Be sure to run `pod lib lint XMGFMBase.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'XMGFMBase'
s.version = '0.3.0'
s.summary = 'XMGFMBase.'
# 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
XMGFMBase.包含了基本的配置, 分类, 工具类等等
DESC
s.homepage = 'https://coding.net/u/seemygo_wangshunzi/p/XMGFMBase'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { '王顺子' => '123@qq.com' }
s.source = { :git => 'https://git.coding.net/seemygo_wangshunzi/XMGFMBase.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '8.0'
s.source_files = 'XMGFMBase/Classes/**/*'
# s.resource_bundles = {
# 'XMGFMBase' => ['XMGFMBase/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
s.dependency 'AFNetworking'
end
-
远程私有库的升级维护(更新提交新代码)
重新升级提交到远程仓库之前要修改.podspec文件的版本号
-
远程私有库依赖问题
依赖第三方框架的时候在.podspec文件后面添加 s.dependency '第三方框架'
-
远程私有库设计优化:整个库分解成多个库,pod的时候pod只需要用到的库
注意比如network子库用到AFN,那么在network子库中添加依赖AFN,而不是在整个库中添加依赖了
-
组件化步骤,以及过程中会遇到的问题
代码加载图片代码:(原因是现在图片已经不再mainBundle里面了)
NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];
NSString *bundleName = [currentBundle.infoDictionary[@"CFBundleName"] stringByAppendingString:@".bundle"];
NSString *path = [currentBundle pathForResource:@"tabbar_np_play@2x.png" ofType:nil inDirectory:bundleName];
UIImage *image = [UIImage imageWithContentsOfFile:path];
-
主骨架组件的使用问题:统一披露API