项目
在 GitHub 查看
nmdias/InfoKit
关于
Strongly Typed access to the Info.plist for iOS, macOS and tvOS.
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.zh-CN.md
原文
基于Swift 4强大的Codable新特性, 在短短60行代码内InfoKit即可提供Info.plist文件的强类型访问.
安装 >> 安装说明 <<
使用
首先根据项目bundle中Info.plist文件的属性类型, 定义Codable协议的结构体.
struct Info: Codable {
let baseUrl: String
let staticUrl: String
}
然后读取Info.plist到该Info结构体:
// Define a Plist
let plist = Plist<Info>()
// Decode it
let info = plist.decode()
// Then access it's properties
info?.baseUrl // http://debug.InfoKit.local
info?.staticUrl // http://debug.static.InfoKit.local
自定义.plist
为了方便性, InfoKit也提供对自定义.plist文件的支持. 假设已经导入ProductIDs.plist文件. 开始根据属性类型定义结构体.
struct Products: Codable {
let foo: String
let bar: String
}
定义Plist, 并指定文件名 例如: ProductIDs
let plist = Plist<Products>("ProductIDs") // Reads `ProductIDs.plist`
let products = plist.decode()
products?.foo // com.InfoKit.foo
products?.bar // com.InfoKit.bar
注意! 用户提供的文件列表必须复制到Bundle, 所以确保设置成
Target Membership.
自定义Bundle
InfoKit默认使用Main Bundle, 但是如果需要可以使用自定义Bundle:
Plist<Products>("ProductIDs", in: bundle)
配置构建
当初始化Plist时, 如果没有Plist名或者没有Bundle名, 如:
Plist<Info>()
InfoKit 将会默认使用Main Bundle中的Info.plist文件来配置构建.
因为该特征, 你可以使用多个Info.plist文件来进行不同的配置仍然有预期的结果.
在example中, 你可以通过在配置选项debug, staging和release之间切换来看到该结果.
开源协议
InfoKit在MIT许可下发布. 详见LICENSE.
探索相关项目
加载中…