快速 URL 查询编码器/解码器,用于 Swift Codable 类型
URLQueryCoder
要求
- iOS 10.0+ / macOS 10.12+ / watchOS 3.0+ / tvOS 10.0+
- Xcode 12.5+
- 斯威夫特 5.1+
用法
struct User: Codable {
var id: Int
var name: String
}
// Encode to URL query
let user = User(id: 123, name: "Neo")
let query = try URLQueryEncoder().encode(user)
// Decode from URL query
let query = "id=123&name=Neo"
let user = try URLQueryDecoder().decode(User.self, from: query)
安装
可可豆荚
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它:
$ gem install cocoapods
要使用 CocoaPods 将 URLQueryCoder 集成到您的 Xcode 项目中,请在您的 :Podfile
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'URLQueryCoder'
end
Finally run the following command:
$ pod install
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate URLQueryCoder into your Xcode project using Carthage, specify it in your :Cartfile
github "almazrafi/URLQueryCoder" ~> 1.0.0
Finally run to build the framework and drag the built into your Xcode project.carthage update
URLQueryCoder.framework
Swift Package Manager
The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrate URLQueryCoder into your Xcode project using Swift Package Manager,
add the following as a dependency to your :Package.swift
.package(url: "https://github.com/almazrafi/URLQueryCoder.git", from: "1.0.0")
and then specify as a dependency of the Target in which you wish to use URLQueryCoder."URLQueryCoder"
Here’s an example :Package.swift
// swift-tools-version:5.1
import PackageDescription
let package = Package(
name: "MyPackage",
products: [
.library(name: "MyPackage", targets: ["MyPackage"])
],
dependencies: [
.package(url: "https://github.com/almazrafi/URLQueryCoder.git", from: "1.0.0")
],
targets: [
.target(name: "MyPackage", dependencies: ["URLQueryCoder"])
]
)
Communication
- If you need help, open an issue.
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
License
URLQueryCoder is available under the MIT license. See the LICENSE file for more info.