CountryKit
分支 | 构建状态 | 代码覆盖率 |
---|---|---|
Master | ||
Develop |
CountryKit
A μlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and emoji.
需求
- iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+
- Xcode 10.2
- Swift 5.0
文档
文档可在 网上找到。
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
CocoaPods 1.1.0+ 是构建 CountryKit 1.0.0+ 所必需的。
要使用 CocoaPods 将 CountryKit 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'CountryKit', '~> 2.0.0'
end
然后,运行以下命令
$ pod install
Carthage
Carthage 是一个去中心化的依赖管理器,它可以构建您的依赖并为您提供二进制框架。
您可以使用以下命令通过 Homebrew 安装 Carthage
$ brew update
$ brew install carthage
要使用 Carthage 将 CountryKit 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它
github "tinrobots/CountryKit" ~> 2.0.0
运行 carthage update
命令来构建框架,并将构建好的 CountryKit.framework
拖到您的 Xcode 项目中。
手动
如果您不希望使用上述任何一个依赖管理器,您可以手动将 CountryKit 集成到您的项目中。
嵌入式框架
- 打开终端,使用
cd
进入顶级项目目录,然后运行以下命令(如果您的项目尚未初始化为 git 仓库)
$ git init
- 通过运行以下命令将 CountryKit 添加为 git 子模块
$ git submodule add https://github.com/tinrobots/CountryKit.git
-
打开新的
CountryKit
文件夹,并将CountryKit.xcodeproj
拖到您的应用程序 Xcode 项目的 Project Navigator 中。它应该显示为嵌套在您的应用程序蓝色项目图标下。它是在所有其他 Xcode 组之上还是之下无关紧要。
-
在项目导航器中选择
CountryKit.xcodeproj
,并验证部署目标与您的应用程序目标是否匹配。 -
接下来,在项目导航器中选择您的应用程序项目(蓝色项目图标),导航到目标配置窗口,并在侧边的“目标”部分中选择应用程序目标。
-
在窗口顶部的标签栏中,打开“通用”选项卡。
-
在“已嵌入的二进制文件”部分下单击
+
按钮。 -
您将看到两个不同的
CountryKit.xcodeproj
文件夹,每个文件夹中都有两个不同版本的CountryKit.framework
,嵌套在Products
文件夹内。您可以选择任意的
Products
文件夹,但选择顶部还是底部的CountryKit.framework
是重要的。 -
为iOS选择顶部的
CountryKit.framework
,为macOS选择底部的。您可以通过检查项目的构建日志来验证您选择了哪个。对于
CountryKit
的构建目标将被列为CountryKit iOS
、CountryKit macOS
、CountryKit tvOS
或CountryKit watchOS
。
用法
import CountryKit
let countryKit = CountryKit()
// list of all countries
let countries = countryKit.countries
// the system current country
let country = countryKit.current
// search a country by its ISO code:
let italy = countryKit.searchByIsoCode("IT")
// iterate over the countries with an iterator:
let iterator = countryKit.makeIterator()
许可协议
CountryKit采用MIT许可协议发布。详细信息请参阅LICENSE。
贡献
欢迎提出pull请求!
通过一个★表达