一个 Swift 微型库,包含所有国家/地区的信息,包括本地化名称、ISO 代码、电话区号、国家/地区代码、国旗图片和 Emoji。
文档 在线可用。
CocoaPods 是 Cocoa 项目的依赖管理工具。您可以使用以下命令安装它
$ gem install cocoapods
构建 CountryKit 1.0.0+ 需要 CocoaPods 1.1.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.1'
end
然后,运行以下命令
$ pod install
Carthage 是一个去中心化的依赖管理工具,它可以构建您的依赖项并为您提供二进制框架。
您可以使用 Homebrew 使用以下命令安装 Carthage
$ brew update
$ brew install carthage
要使用 Carthage 将 CountryKit 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它
github "alemar11/CountryKit" ~> 2.0.1
运行 carthage update
来构建框架,并将构建的 CountryKit.framework
拖到您的 Xcode 项目中。
如果您不想使用上述任何依赖管理工具,您可以手动将 CountryKit 集成到您的项目中。
cd
进入您的顶级项目目录,并运行以下命令“如果”您的项目未初始化为 git 仓库$ git init
$ git submodule add https://github.com/alemar11/CountryKit.git
打开新的 CountryKit
文件夹,并将 CountryKit.xcodeproj
拖到应用程序 Xcode 项目的项目导航器中。
它应该嵌套在应用程序的蓝色项目图标下。它在所有其他 Xcode 组之上还是之下无关紧要。
在项目导航器中选择 CountryKit.xcodeproj
,并验证部署目标是否与应用程序目标匹配。
接下来,在项目导航器中选择您的应用程序项目(蓝色项目图标)以导航到目标配置窗口,然后在侧边栏中的“Targets”标题下选择应用程序目标。
在该窗口顶部的选项卡栏中,打开“General”面板。
单击“Embedded Binaries”部分下的 +
按钮。
您将看到两个不同的 CountryKit.xcodeproj
文件夹,每个文件夹都有两个不同版本的 CountryKit.framework
嵌套在一个 Products
文件夹中。
从哪个
Products
文件夹中选择无关紧要,但选择顶部还是底部CountryKit.framework
确实很重要。
选择顶部的 CountryKit.framework
用于 iOS,选择底部的用于 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 Request!
用 ★ 显示您的 ❤