podspec文件的写法详解

2024-05-27 02:32
文章标签 详解 写法 podspec

本文主要是介绍podspec文件的写法详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

创建pod库的时候会用到podspec文件将lib中用到的包括资源、源码、需要引用的framework,以及第三库等等组织起来。这篇文章会详细的解释一下podspec的写法。


1、podspec文件的创建


(1)pod命令创建,pod spec create [文件名]

这种方式创建出的podspec文件会带有大量的注释


(2)linux命令创建文件,touch  **.podspec
这种方式创建出了一个空的podspec文件,熟练之后可以采用这种方式。
2、podspec内容编辑
下面是从新建成功的的podspec中复制过来的,pod升级到1.1之后在新建的podspec文件中加了详细的解释,几乎不用看另外的文档就能编写podspec文件。新建的文件中未被注释的是必填项,其他为非必填项。

#
#  Be sure to run `pod spec lint TestPodSpec.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         = "TestPodSpec"s.version      = "0.0.1"s.summary      = "A short description of TestPodSpec."# 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  = <<-DESCDESCs.homepage     = "http://EXAMPLE/TestPodSpec"# 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 (example)"# 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             = { "" => "" }# Or just: s.author    = ""# s.authors            = { "" => "" }# s.social_media_url   = "http://twitter.com/"# ――― 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, "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 where the source should be retrieved.#  Supports git, hg, bzr, svn and HTTP.#s.source       = { :git => "http://EXAMPLE/TestPodSpec.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.#s.source_files  = "Classes", "Classes/**/*.{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  = "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.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }# s.dependency "JSONKit", "~> 1.4"end


3、上文中未涉及到的内容编写

(1)、部分文件非ARC

方案1:将require_arc设为false,同时指定需要arc的文件夹或者文件

spec.requires_arc = false
#spec.requires_arc = ['Classes/ARC/*', 'Classes/ARC1/*']
#spec.requires_arc = 'Classes/Arc'


方案2:将require_arc设为yes,同时指定除外的文件,不过使用这个方法,会导致非ARC文件被移除出原有的目录结构,不推荐使用。目前官方也是推荐采用方案1.


(2)、使用了第三方静态库,但提供方并未提供pod方案集成,需要手动导入,这个时候就需要加入vendored_lib、aries指定

  s.vendored_libraries = 'Classes/**.a', 'Classes/**.a'


(3)、lib比较大,由很多文件夹构成并且文件夹相互之间并不独立,如果用subspec实现文件夹区分,在后期lint的过程中无法通过验证,除非只在本地使用。当然如果只在本地使用也不用考虑文件夹,pod会把目录结构原原本本的导入到工程里面去。





这篇关于podspec文件的写法详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1006273

相关文章

Java使用ANTLR4对Lua脚本语法校验详解

《Java使用ANTLR4对Lua脚本语法校验详解》ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件,下面就跟随小编一起看看Java如何使用ANTLR4对Lua脚本... 目录什么是ANTLR?第一个例子ANTLR4 的工作流程Lua脚本语法校验准备一个Lua Gramm

一文详解如何在Python中从字符串中提取部分内容

《一文详解如何在Python中从字符串中提取部分内容》:本文主要介绍如何在Python中从字符串中提取部分内容的相关资料,包括使用正则表达式、Pyparsing库、AST(抽象语法树)、字符串操作... 目录前言解决方案方法一:使用正则表达式方法二:使用 Pyparsing方法三:使用 AST方法四:使用字

Python列表去重的4种核心方法与实战指南详解

《Python列表去重的4种核心方法与实战指南详解》在Python开发中,处理列表数据时经常需要去除重复元素,本文将详细介绍4种最实用的列表去重方法,有需要的小伙伴可以根据自己的需要进行选择... 目录方法1:集合(set)去重法(最快速)方法2:顺序遍历法(保持顺序)方法3:副本删除法(原地修改)方法4:

python logging模块详解及其日志定时清理方式

《pythonlogging模块详解及其日志定时清理方式》:本文主要介绍pythonlogging模块详解及其日志定时清理方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录python logging模块及日志定时清理1.创建logger对象2.logging.basicCo

前端CSS Grid 布局示例详解

《前端CSSGrid布局示例详解》CSSGrid是一种二维布局系统,可以同时控制行和列,相比Flex(一维布局),更适合用在整体页面布局或复杂模块结构中,:本文主要介绍前端CSSGri... 目录css Grid 布局详解(通俗易懂版)一、概述二、基础概念三、创建 Grid 容器四、定义网格行和列五、设置行

Node.js 数据库 CRUD 项目示例详解(完美解决方案)

《Node.js数据库CRUD项目示例详解(完美解决方案)》:本文主要介绍Node.js数据库CRUD项目示例详解(完美解决方案),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考... 目录项目结构1. 初始化项目2. 配置数据库连接 (config/db.js)3. 创建模型 (models/

SQL表间关联查询实例详解

《SQL表间关联查询实例详解》本文主要讲解SQL语句中常用的表间关联查询方式,包括:左连接(leftjoin)、右连接(rightjoin)、全连接(fulljoin)、内连接(innerjoin)、... 目录简介样例准备左外连接右外连接全外连接内连接交叉连接自然连接简介本文主要讲解SQL语句中常用的表

shell编程之函数与数组的使用详解

《shell编程之函数与数组的使用详解》:本文主要介绍shell编程之函数与数组的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录shell函数函数的用法俩个数求和系统资源监控并报警函数函数变量的作用范围函数的参数递归函数shell数组获取数组的长度读取某下的

Python中局部变量和全局变量举例详解

《Python中局部变量和全局变量举例详解》:本文主要介绍如何通过一个简单的Python代码示例来解释命名空间和作用域的概念,它详细说明了内置名称、全局名称、局部名称以及它们之间的查找顺序,文中通... 目录引入例子拆解源码运行结果如下图代码解析 python3命名空间和作用域命名空间命名空间查找顺序命名空

SpringRetry重试机制之@Retryable注解与重试策略详解

《SpringRetry重试机制之@Retryable注解与重试策略详解》本文将详细介绍SpringRetry的重试机制,特别是@Retryable注解的使用及各种重试策略的配置,帮助开发者构建更加健... 目录引言一、SpringRetry基础知识二、启用SpringRetry三、@Retryable注解