在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:thoughtbot/Argo开源软件地址:https://github.com/thoughtbot/Argo开源编程语言:Swift 95.3%开源软件介绍:ArgoArgo is a library that lets you extract models from JSON or similar structures in a way that's concise, type-safe, and easy to extend. Using Argo, you won't need to write validation code to ensure that incoming data is of the right type, or to make sure required data fields aren't turning up empty. Argo uses Swift's expressive type system to do that for you, and reports back explicit failure states in case it doesn't find what you've told it to expect. Argo is the Greek word for swift and the name of the ship used by Jason, son of Aeson, of the Argonauts. Aeson is the JSON parsing library in Haskell that inspired Argo, much like Aeson inspired his son Jason. Version CompatibilityNote that we're aggressive about pushing Here is the current Swift compatibility breakdown:
InstallationCarthageAdd the following to your Cartfile:
Then run Follow the current instructions in Carthage's README for up to date installation instructions. Note that if you are using newer versions of Argo, you will need to link both
CocoaPodsAdd the following to your Podfile: pod 'Argo' You will also need to make sure you're opting into using frameworks: use_frameworks! Then run Git SubmodulesI guess you could do it this way if that's your thing. Add this repo as a submodule, and add the project file to your workspace. You
can then link against You will need to do the same for Runes if you are using newer versions of Argo. Usage tl;dr:Please note: the example below requires an additional, external module named
Curry which lets us use the It also imports Runes, which is a dependency of Argo in newer versions. If you are using an older version of Argo, you might not need that import. import Argo
import Curry
import Runes
struct User {
let id: Int
let name: String
let email: String?
let role: Role
let companyName: String
let friends: [User]
}
extension User: Decodable {
static func decode(_ json: JSON) -> Decoded<User> {
return curry(User.init)
<^> json <| "id"
<*> json <| "name"
<*> json <|? "email" // Use ? for parsing optional values
<*> json <| "role" // Custom types that also conform to Decodable just work
<*> json <| ["company", "name"] // Parse nested objects
<*> json <|| "friends" // parse arrays of objects
}
}
// Wherever you receive JSON data:
let json: Any? = try? NSJSONSerialization.JSONObjectWithData(data, options: [])
if let j: Any = json {
let user: User? = decode(j)
} For more information, see the Documentation ContributingSee the CONTRIBUTING document. Thank you, contributors! LicenseArgo is Copyright (c) 2015 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file. AboutArgo is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc. We love open source software! See our other projects or look at our product case studies and hire us to help build your iOS app. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论