一快速編譯
1.背景
為了實現各模塊之家的解耦和各模塊和App之間的快速可插拔要求,設計了此方案。
此方案能夠解決如下問題:
a1.模塊的單獨編碼和模塊的單獨編譯;
a2.需要應用模塊的時候能夠通過一行命令就能快速接入某個功能模塊到App中,不需要的時候就能快速的去掉該模塊在工程中的引用;
a3.能夠按需引用功能模塊,自動生成工程代碼,可實現定制項目的快速響應。
2.實現方案
a1.實現思路:使用cocoapods本地倉庫的方式,把各個模塊在本地創建倉庫,實現模塊功能的本地管理和本地編譯;再通過Podfile install命令實現功能模塊的快速引用和快速刪除。
a2.本地倉庫的創建方法
aa1:使用xcode創建一個工程,工程名字就叫cocospods;
在cocospods目錄下創建LocalLib目錄,用來放置各個模塊的代碼;
在LocalLib下面,創建pod庫的代碼名稱,比如叫download。
代碼目錄如圖:
aa2:在download目錄下面,創建podspec文件。
創建命令:pod?spec?create?download
aa3:修改download. podspec文件
.podspec修改要點如下:
#
#Be sure to run `pod spec lint upload.podspec' to ensure this is a
#valid spec and to remove all comments including this before submittingthe spec.
#
#To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
#To see working Podspecs in the CocoaPods repo seehttps://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |s|
#―――Spec Metadata――――――――――――――――――――――――――――――――――――――――――――――――――――――――――#
#
#These will help people to findyour library, and whilst it
#can feel like a chore to fillin it's definitely to your advantage. The
#summary should be tweet-length,and the description more in depth.
#
s.name="upload"
s.version= "0.0.1"
s.summary= "A shortdescription of upload."
# This description is used to generate tags and improve search results.
#* Think: What does it do? Whydid you write it? What is the focus?
#* Try to keep it short, snappyand to the point.
#* Write the descriptionbetween the DESC delimiters below.
#* Finally, don't worry aboutthe indent, CocoaPods strips it!
s.description= 'upload test'
s.homepage='http://EXAMPLE/upload'[11]
# s.screenshots="www.example.com/screenshots_1.gif","www.example.com/screenshots_2.gif"
#―――Spec License―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――#
#
#Licensing your code isimportant. See http://choosealicense.com for more info.
#CocoaPods will detect a licensefile if there is a named LICENSE*
#Popular ones are 'MIT', 'BSD'and 'Apache License, Version 2.0'.
#
# s.license= { :type =>"MIT", :file => "FILE_LICENSE" }
#―――Author Metadata―――――――――――――――――――――――――――――――――――――――――――――――――――――――――#
#
#Specify the authors of thelibrary, with email addresses. Email addresses
#of the authors are extractedfrom the SCM log. E.g. $ git log. CocoaPods also
#accepts just a name if you'drather not provide an email address.
#
#Specify a social_media_urlwhere others can refer to, for example a twitter
#profile URL.
#
# Or just: s.author= 'William'
# s.authors= { 'William' => '' }
# s.social_media_url= 'http://twitter.com/William'[13]
#―――Platform Specifics―――――――――――――――――――――――――――――――――――――――――――――――――――――――#
#
#If this Pod runs only on iOS orOS X, then specify the platform and
#the deployment target. You canoptionally include the target after the platform.
#
# s.platform= :ios, '5.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 wherethe source should be retrieved.
#Supports git, hg, bzr, svn andHTTP.
#
s.source= { :git =>""[15], :tag => "#{s.version}" }
#―――Source Code――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――#
#
#CocoaPods is smart about how itincludes source code. For source files
#giving a folder will includeany swift, h, m, mm, c & cpp files.
#For header files it willinclude any header in the folder.
#Not including thepublic_header_files will make all headers public.
#
s.source_files="Classes"[16], "Classes/**/*.{h,m}"
s.exclude_files = "Classes/Exclude"
# s.public_header_files = "Classes/**/*.h"
#―――Resources――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――#
#
#A list of resources includedwith the Pod. These are copied into the
#target bundle with a buildphase script. Anything else will be cleaned.
#You can preserve files frombeing 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 withframeworks, 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 oncompiler flags you can set them in the xcconfig hash
#where they will only apply toyour library. If you depend on other Podspecs
#you can include multipledependencies to ensure it works.
# s.requires_arc = true
# s.xcconfig = { "HEADER_SEARCH_PATHS" =>"$(SDKROOT)/usr/include/libxml2" }
# s.dependency "JSONKit", "~> 1.4"
end
3.附件、參考信息
參考鏈接:http://blog.csdn.net/veryitman/article/details/51407078
Podfile文件信息:
platform :ios,'7.0'
#use_frameworks!
target'cocospods' do
# download模塊
pod 'download', :path =>'./LocalLib/download/'
# upload模塊
pod ‘upload’, :path =>'./LocalLib/upload/'
#pod 'core_lib_spec', :svn =>'http://svn.ids111.com/o2o/client/ios/trunks/master/Frameworks/CoreLibrary'
end
[11]原先為"http://EXAMPLE/upload",編譯問題把“”改為‘’
[12]原先為"MIT (example)",去掉example
[13]把雙引號“”改為單引號‘’,編譯問題,去掉沒有必要的信息
[14]把雙引號“”改為單引號‘’,編譯問題。
[15]去掉里面的內容
[16]源代碼文件夾名稱