freshos / arrow Goto Github PK
View Code? Open in Web Editor NEW๐น Parse JSON with style
License: MIT License
๐น Parse JSON with style
License: MIT License
Using a Docker container to build my app with a reference to Arrow module, I get the following error:
Dockerfile:
FROM swift:latest as builder
WORKDIR /app
COPY ./Sources Sources/
COPY Package.swift Package.swift
RUN swift build -c release
CMD ["s"]h
Error:
/app/.build/checkouts/Arrow/Sources/Arrow/Arrow.swift:10:8: error: no such module 'CoreGraphics'
Hi, I'm trying to iterate a JSON like so
if let collection = json.collection {
for jsonEntry in collection {
// things
}
}
and it says there is no member 'collection' in json. Checking the source code here shows that there actually is a 'collection'. I tried readding the libraries through Carthage as well but no dice.
I need to parse dates which are not in the current time zone, so I need to set the timezone on Arrow's dateFormatter, but as it is I can't.
Hi, sorry to ask such a dumb question, but I can't figure out how to do a simple decode from a string containing my json to my model object:
struct doh: Codable {
var homer = ""
}
extension doh : ArrowParsable {
public mutating func deserialize(_ json: JSON) {
homer <-- json["homer"]
}
}
now to create one:
let myJson = "{ \"homer\": \"simpson\"}"
var aSimpson = doh()
aSimpson.deserialize(JSON(myJson)!)
this doesn't work! How do I create a doh
object from the myJson
string?
Thanks.
I'm using Moya + RxSwift and would like to use Arrow to do the parsing. Has anyone ever tried this?
Thanks.
Find a way to get notified if a parsing error occurs, for example a missing key
Hi! In some cases optional var
s for custom models are needed in addition to plain swift types.
For example:
struct Profile {
var identifier = 0
var stats: Stats? = nil
}
extension Profile: ArrowParsable {
init(json: JSON) {
identifier <-- json["id"]
stats <== json["stats"] // error
}
}
The current implementation gives the following error for the above code: Cannot convert value of type 'Stats?' to expected argument type 'inout _'
.
netsted values:
value <-- json["user.name"]
How to deal with the following situation
{
"user": {
"name": "Joannis"
}
}
{
"user.name": "Joannis"
}
Hi,
I'm wondering me to how I can cast the json values!
createdUser.id = Int32((json["id"]?.data as? Int32)!)
does not work.
id <-- Int32((json["id"]?.data as? Int32)!)
does not work.
id <--json["id"]
does not work.
Each time I get this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[User setId:]: unrecognized selector sent to instance 0x60400047d100'
So do you have an idea about that? I'm surprised that nobody got the present error by the past :)
My rest service returns id (so Int32 for me on swift) and some dates that I have to parse.
Any Alternatives for base json attributes ?
Hi,
the newest version of Arrow (2.0.1) doesn't compile with snapshot 4-12.
โ swift build
Cloning https://github.com/s4cha/Arrow.git
Resolved version: 2.0.1
Compiling Swift Module 'Arrow' (2 sources)
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:34:33: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T>(inout left: T, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:43:33: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T>(inout left: T?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:47:30: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
func parseType<T>(inout left:T?,right:JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:65:51: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T: RawRepresentable>(inout left: T, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:73:51: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T: RawRepresentable>(inout left: T?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:83:46: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T:ArrowParsable>(inout left:T, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:91:46: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T:ArrowParsable>(inout left:T?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:101:46: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T:ArrowParsable>(inout left:[T], right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:113:46: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T:ArrowParsable>(inout left:[T]?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:127:30: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- (inout left: NSDate, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:135:30: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- (inout left: NSDate?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:139:27: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
func parseDate(inout left:NSDate?,right:JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:163:30: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- (inout left: NSURL, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:171:30: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- (inout left: NSURL?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:175:26: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
func parseURL(inout left:NSURL?, right:JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:187:32: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
func parseArray<T>(inout left: [T]?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:196:33: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T>(inout left: [T], right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:204:33: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T>(inout left: [T]?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:66:17: error: 'RawValue' is not a member type of 'T'
var temp: T.RawValue? = nil
~ ^
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:74:17: error: 'RawValue' is not a member type of 'T'
var temp: T.RawValue? = nil
~ ^
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:85:17: error: type 'T' has no member 'init'
var t = T.init()
^ ~~~~
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:93:17: error: type 'T' has no member 'init'
var t = T.init()
^ ~~~~
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:150:27: error: value of type 'NSDateFormatter' has no member 'dateFromString'
if let date = dateFormatter.dateFromString(s) {
^~~~~~~~~~~~~ ~~~~~~~~~~~~~~
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:34:33: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T>(inout left: T, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:43:33: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T>(inout left: T?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:47:30: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
func parseType<T>(inout left:T?,right:JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:65:51: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T: RawRepresentable>(inout left: T, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:73:51: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T: RawRepresentable>(inout left: T?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:83:46: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T:ArrowParsable>(inout left:T, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:91:46: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T:ArrowParsable>(inout left:T?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:101:46: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T:ArrowParsable>(inout left:[T], right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:113:46: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T:ArrowParsable>(inout left:[T]?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:127:30: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- (inout left: NSDate, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:135:30: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- (inout left: NSDate?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:139:27: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
func parseDate(inout left:NSDate?,right:JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:163:30: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- (inout left: NSURL, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:171:30: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- (inout left: NSURL?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:175:26: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
func parseURL(inout left:NSURL?, right:JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:187:32: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
func parseArray<T>(inout left: [T]?, right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:196:33: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T>(inout left: [T], right: JSON?) {
~~~~~ ^
inout
/Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/Packages/Arrow-2.0.1/Source/Arrow.swift:204:33: error: 'inout' before a parameter name is not allowed, place it before the parameter type instead
public func <-- <T>(inout left: [T]?, right: JSON?) {
~~~~~ ^
inout
<unknown>:0: error: build had 1 command failures
error: exit(1): /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-04-12-a.xctoolchain/usr/bin/swift-build-tool -f /Users/aevitas/Desktop/Projects/Swift/Server/league-downloader/.build/debug.yaml default
Is the plan to support Swift3?
Does this library allow to serialize a JSON string to an object?
Hello,
At WWDC23 Apple announced that apps and SDKs that make use of certain "required reason" APIs etc will need to provide a privacy manifest.
Does UIView-Shimmer need to include this manifest?
Here are some useful references:
https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_data_use_in_privacy_manifests
https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api
https://developer.apple.com/videos/play/wwdc2023/10060/
Thanks
TODO
Look for all differences with codable and list them.
Having compared Arrow with Codable in a big iOS App, I still believe there's an advantage using Arrow.
@maxkonovalov I would love to know your feelings on Codable vs Arrow :)
Having trouble of parsing an array of enums.
var weekdays: [WeekDay]?
Response:
{
"weekdays": [1, 3]
}
Parse:
self.weekdays <-- json["weekdays"]
Outcome is nil. :/
Swift 4 is a game changer !
We'll have to look at how Arrow integrates in this new ecosystem.
Hi,
I'm trying to parse my custom models but <== json["customModel"]
not working for me!
Example :
struct oneModel: ArrowParsable {
var customModel = CustomMedel()
init() {
}
init(json: JSON) {
customModel <== json["customModel"]
}
}
struct CustomModel: ArrowParsable {
var id = Int()
var title = String()
init() {
}
init(json: JSON) {
id <-- json["id"]
title <-- json["title"]
}
}
But I can use json.valueForKeyPath without any problems!!!
The latest tag 3.0.3
is missing from master
branch and also from CocoaPods specs repo, it shows v.3.0.2 only. Because of this the ws pod fails to install:
[!] Unable to find a specification for
Arrow3.0.3
depended upon byws
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.