美学原理cocoapods系列教程—spec文件

cocoapods系列教程—安装及用
cocoapods系列教程—Podfile文件
cocoapods系列教程—Podfile.lock文件 和 Spec
Repo
cocoapods系列教程—spec文件
cocoapods系列教程—原理篇
cocoapods系列教程—让祥和之开源框架支持cocoapods
cocoapods系列教程—模块化设计
cocoapods系列教程—创建私有pods

下介绍spec文件之详细设置.基本上是依据官网翻译过来的,有啊尴尬还望指点

  • name

spec.name = 'AFNetworking'
  • 版本

spec.version = '0.0.1'
  • 支持的cocoapods的版本

spec.cocoapods_version = '>= 0.36'
  • 配备信息,根据个体用填写

spec.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' }

spec.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '"
$(SRCROOT)/libs/Frameworks/Huoyan"' }   

spec.xcconfig  = { 'LIBRARY_SEARCH_PATHS' => '"$(PODS_ROOT)/iOS_Util/iOS_Util/AMR/lib"' }

spec.xcconfig  = { "HEADER_SEARCH_PATHS" => "${PODS_ROOT}/boost" }
  • 作者信息

spec.author = 'Darth Vader'

若有差不多只作者,可以这样描绘

spec.authors = 'Darth Vader', 'Wookiee'

spec.authors = { 'Darth Vader' => 'darthvader@darkside.com',
                 'Wookiee'     => 'wookiee@aggrrttaaggrrt.com' }
  • 多媒体地址,如果地方是twitter,发布版会生通知

spec.social_media_url = 'https://twitter.com/cocoapods'

spec.social_media_url = 'https://groups.google.com/forum/#!forum/cocoapods'
  • 特许,一般MIT,默认与spec文件在平目录下

spec.license = 'MIT'
  • 指定许可文件

spec.license = { :type => 'MIT', :file => 'MIT-LICENSE.txt' }

指定许可文件的内容

spec.license = { :type => 'MIT', :text => <<-LICENSE
                   Copyright 2012
                   Permission is granted to...
                 LICENSE
               }
  • 品种主页

spec.homepage = 'http://www.example.com'
  • 花色git地址,tag值与spec.verison版本相同

spec.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git',
                :tag => spec.version.to_s }

种git地址,tag值以v开头,支持子模块(子模块是git的子模块)

spec.source = { :git => 'https://github.com/typhoon-framework/Typhoon.git',
                :tag => "v#{spec.version}", :submodules => true }

项目svn地址

spec.source = { :svn => 'http://svn.code.sf.net/p/polyclipping/code', :tag => '4.8.8' }

列压缩包地址

spec.source = { :http => 'http://dev.wechatapp.com/download/sdk/WeChat_SDK_iOS_en.zip' }

点名压缩包地址,并校验hash值,支持sha1 和 sha256

spec.source = { :http => 'http://dev.wechatapp.com/download/sdk/WeChat_SDK_iOS_en.zip',
                :sha1 => '7e21857fe11a511f472cfd7cfa2d979bd7ab7d96' }

指定为本土地址

podspec :path => '/Documents/PrettyKit/PrettyKit.podspec'
  • 简介

spec.summary = 'Computes the meaning of life.'
  • 详细描述

spec.description = <<-DESC

                   这里写描述内容

                   DESC
  • 单个截图

spec.screenshot  = 'http://dl.dropbox.com/u/378729/MBProgressHUD/1.png'
  • 大抵只截图

spec.screenshots = [ 'http://dl.dropbox.com/u/378729/MBProgressHUD/1.png',
                     'http://dl.dropbox.com/u/378729/MBProgressHUD/2.png' ]
  • 文档说明

spec.documentation_url = 'http://www.example.com/docs.html'
  • prepare_command,在pod文件下充斥了后,执行的授命,原文如下

A bash script that will be executed after the Pod is downloaded. This command can be used to create, delete and modify any file downloaded and will be ran before any paths for other file attributes of the specification are collected.

This command is executed before the Pod is cleaned and before the Pods project is created. The working directory is the root of the Pod.

If the pod is installed with the :path option this command will not be executed.

单个命令

spec.prepare_command = 'ruby build_files.rb'

多长条命令

spec.prepare_command = <<-CMD
                        sed -i 's/MyNameSpacedHeader/Header/g' ./**/*.h
                        sed -i 's/MyNameOtherSpacedHeader/OtherHeader/g' ./**/*.h
                   CMD
  • 是不是过期

spec.deprecated = true
  • 支持之平台,如果未写默认支持有平台

spec.platform = :ios //仅支持ios

支持多只平台

spec.ios.deployment_target = '6.0'

spec.osx.deployment_target = '10.8'
  • 依之老三着

spec.dependency 'AFNetworking', '~> 1.0'

点名某个平台的仗

spec.ios.dependency 'MBProgressHUD', '~> 0.5'
  • 是不是是ARC,默认true,如果非是,会活动抬高-fno-objc-arc compiler flag

spec.requires_arc = true

部分是ARC

spec.requires_arc = false
spec.requires_arc = 'Classes/Arc'   //该文件夹下是ARC,其它非ARC
spec.requires_arc = ['Classes/*ARC.m', 'Classes/ARC.mm']
  • 仰的体系的框架

spec.ios.framework = 'CFNetwork'

多单framework,用逗号分开

spec.frameworks = 'QuartzCore', 'CoreData'
  • weak_frameworks
    一旦在胜版本的OS中调用新增的法力,并且于亚版本的OS中依旧会运转,那么快要用到weak_frameworks.如果引用的少数类或接口在亚版本被连无支持,对于无支持之接口,可以以运行的当儿判断,这样程序不会见拧,如果无weak引用,程序于低版本下启动之上便会见崩溃掉

spec.weak_framework = 'MessageUI'
  • libraries 比如libz,sqlite3.0等,多只用逗号分开

spec.libraries = 'xml2', 'z'  //z表示libz.tdb,后缀不需要,lib开头的省略lib
  • compiler_flags

spec.compiler_flags = '-DOS_OBJECT_USE_OBJC=0', '-Wno-format'
  • prefix_header_contents 类似于pch,文件,多个用逗号隔开

spec.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>'

否得以这么形容:

s.prefix_header_contents = <<-EOS
 #ifdef __OBJC__
 #import "SGExtension.h"    //SGExtension包含了所有头文件
 #endif 
EOS
end
  • 指定pch文件

spec.prefix_header_file = 'iphone/include/prefix.pch'
  • 源文件

spec.source_files = 'Classes/**/*.{h,m}'
spec.source_files = 'Classes/**/*.{h,m}', 'More_Classes/**/*.{h,m}'
  • 文本匹配
    • *相当有文件
    • c*匹配因名字C开头的文件
    • *c配合为名字c结尾的文书
    • *c*相当有名字包含c的文本
    • **文本夹和递归子文件夹
    • ?随便一个字符(注意是一个字符)
    • [set] 匹配多独字符,支持取反
    • {p,q} 匹配名字包括p 或者 q的文件

例子:

"JSONKit.?"    #=> ["JSONKit.h", "JSONKit.m"]   //JSONKit.字符
"*.[a-z][a-z]" #=> ["CHANGELOG.md", "README.md"]//.两个a-z的字母
"*.[^m]*"      #=> ["JSONKit.h"]                //.不是m的字符
"*.{h,m}"      #=> ["JSONKit.h", "JSONKit.m"]   //包含.h或者.m
"*"            #=> ["CHANGELOG.md", "JSONKit.h", "JSONKit.m", "README.md"]//所有文件
  • 公有头文件

spec.public_header_files = 'Headers/Public/*.h'
  • 私有头文件

spec.private_header_files = 'Headers/Private/*.h'
  • 好的还是第三在framework,比qqSDK的TencentOpenAPI.framework

spec.vendored_frameworks = 'MyFramework.framework','TheirFramework.framework'
  • 温馨的要第三方.a文件,比如微信SDK的.a文件

spec.vendored_libraries = 'libProj4.a', 'libJavaScriptCore.a'
  • 资源文件,比如图片

spec.ios.resource_bundle = { 'MapBox' => 'MapView/Map/Resources/*.png' }

多个路径        
spec.resource_bundles = {
    'MapBox' => ['MapView/Map/Resources/*.png'],
    'OtherResources' => ['MapView/Map/OtherResources/*.png']
  }

这种措施资源文件会被以bundle的款式参加到品种蒙去,官方建议用的法门,主要是预防和用户的命名方式冲突

  • 资源文件另一样种艺术,这种比普遍

spec.resource = 'Resources/HockeySDK.bundle'
spec.resources = ['Images/*.png', 'Sounds/*']