Coder Social home page Coder Social logo

freshos / arrow Goto Github PK

View Code? Open in Web Editor NEW
385.0 11.0 28.0 21.74 MB

๐Ÿน Parse JSON with style

License: MIT License

Swift 100.00%
json json-parsing ios swift micro-framework simple arrow mapping decoding unbox freshos type-inference swiftyjson objectmapper

arrow's Introduction

Arrow

Arrow

Language: Swift 5 Platform: iOS 8+ SPM compatible Carthage compatible Cocoapods compatible Build Status codebeat badge License: MIT Release version

Reason - Example - Installation

identifier <-- json["id"]
name <-- json["name"]
stats <-- json["stats"]

Because parsing JSON in Swift is full of unecessary if lets, obvious casts and nil-checks
There must be a better way

Try it

Arrow is part of freshOS iOS toolset. Try it in an example App! Download Starter Project

How

By using a simple arrow operator that takes care of the boilerplate code for us.
Json mapping code becomes concise and maintainable โค๏ธ

Why use Arrow

  • Infers types
  • Leaves your models clean
  • Handles custom & nested models
  • Dot and array syntax
  • Pure Swift, Simple & Lightweight

Example

Swift Model

struct Profile {
    var identifier = 0
    var name = ""
    var link:NSURL?
    var weekday:WeekDay = .Monday
    var stats = Stats()
    var phoneNumbers = [PhoneNumber]()
}

JSON File

{
    "id": 15678,
    "name": "John Doe",
    "link": "https://apple.com/steve",
    "weekdayInt" : 3,
    "stats": {
        "numberOfFriends": 163,
        "numberOfFans": 10987
    },
    "phoneNumbers": [{
                     "label": "house",
                     "number": "9809876545"
                     }, {
                     "label": "cell",
                     "number": "0908070656"
                     }, {
                     "label": "work",
                     "number": "0916570656"
    }]
}

Before (Chaos)

var profile = Profile()

// Int
if let id = json["id"] as? Int {
    profile.identifier = id
}  
// String
if let name = json["name"] as? String {
    profile.name = name
}
// NSURL
if let link = json["link"] as? String, url = NSURL(string:link)  {
    profile.link = link
}
// Enum
if let weekdayInt = json["weekdayInt"] as? Int, weekday = WeekDay(rawValue:weekdayInt) {
    profile.weekday = weekday
}
// Custom nested object
if let statsJson = json["stats"] as? AnyObject {
    if let numberOfFans = statsJson["numberOfFans"] as? Int {
        profile.stats.numberOfFans = numberOfFans
    }
    if let numberOfFriends = statsJson["numberOfFriends"] as? Int {
        profile.stats.numberOfFriends = numberOfFriends
    }
}
// Array of custom nested object
if let pns = json["phoneNumbers"] as? [AnyObject] {
    for pn in pns {
        phoneNumbers.append(PhoneNumber(json: pn))
    }
}

After ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰

extension Profile:ArrowParsable {
    mutating func deserialize(_ json: JSON) {
        identifier <-- json["id"]
        link <-- json["link"]
        name <-- json["name"]
        weekday <-- json["weekdayInt"]
        stats <- json["stats"]
        phoneNumbers <-- json["phoneNumbers"]
    }
}

Usage

let profile = Profile()
profile.deserialize(json)

Installation

The Swift Package Manager (SPM) is now the official way to install Arrow. The other package managers are now deprecated as of 5.1.2 and won't be supported in future versions.

Swift Package Manager

Xcode > File > Swift Packages > Add Package Dependency... > Paste https://github.com/freshOS/Arrow

Carthage - Deprecated

github "freshOS/Arrow"

CocoaPods - Deprecated

target 'MyApp'
pod 'Arrow'
use_frameworks!

How Does That Work

Notice earlier we typed :

stats <-- json["stats"]

That's because we created and extension "Stats+Arrow.swift" enabling us to use the Arrow Operator

//  Stats+Arrow.swift

import Foundation

extension Stats:ArrowParsable {
    mutating func deserialize(json: JSON) {
        numberOfFriends <-- json["numberOfFriends"]
        numberOfFans <-- json["numberOfFans"]
    }
}

Flexible you said

  • DO I have to use the <-- for my sub models
  • Nope, you could write it like so if you wanted :
stats.numberOfFriends <-- json["stats.numberOfFriends"]
stats.numberOfFans <-- json["stats.numberOfFans"]

Date Parsing

Globally

// Configure Global Date Parsing with one of those
Arrow.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ")
Arrow.setUseTimeIntervalSinceReferenceDate(true)
Arrow.setDateFormatter(aDateFormatter)

// Then later dates can be parsed form custom date format or timestamps automatically ๐ŸŽ‰
let json:JSON = JSON(["date": "2013-06-07T16:38:40+02:00", "timestamp": 392308720])
date1 <-- json["date"]
date2 <-- json["timestamp"]

On a per-key basis

createdAt <-- json["created_at"]?.dateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ")
createdAt <-- json["created_at"]?.dateFormatter(aCustomDateFormatter)

Just provide it on a case per case basis ! ๐ŸŽ‰

Accessing JSON values

Nested values

value <-- json["nested.nested.nested.nestedValue"]

Object at index

value <-- json[12]

Combine both

value <-- json[1]?["someKey"]?[2]?["something.other"]

Looping on Array

if let collection = json.collection {
    for jsonEntry in collection {
        //Do something
    }
}

Swift Version

  • Swift 2 -> version 2.0.3
  • Swift 3 -> version 3.0.5
  • Swift 4 -> version 4.0.0
  • Swift 4.1 -> version 4.1.0
  • Swift 4.2 -> version 4.2.0
  • Swift 5.0 -> version 5.0.0
  • Swift 5.1 -> version 5.1.0
  • Swift 5.1.3 -> version 5.1.1
  • Swift 5.3 -> version 6.0.0

Acknowledgements

This wouldn't exist without YannickDot, Damien-nd and maxkonovalov

Backers

Like the project? Offer coffee or support us with a monthly donation and help us continue our activities :)

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site :)

arrow's People

Contributors

aciidgh avatar ezisazis avatar maxkonovalov avatar michalsrutek avatar peteallport avatar s4cha avatar viktorgardart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arrow's Issues

Swift 4

Swift 4 is a game changer !
We'll have to look at how Arrow integrates in this new ecosystem.

Privacy Manifest

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

Cannot cast json to other type

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.

<== not working for me

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!!!

netsted values problem

netsted values:
value <-- json["user.name"]

How to deal with the following situation

{
    "user": {
        "name": "Joannis"
    }
}
{
    "user.name": "Joannis"
}

Codable

TODO

Look for all differences with codable and list them.

Codable

  • 1 parsing fails all fails
  • Fine grained error handling
  • Need 1 custom parsing need to write all encodable method
  • Default parsing matching existing keys
  • No type inference (apart from dates)
  • Yields a new object
  • Quite verbose

Arrow

  • Best effort parsing, ignoring fails
  • No error handling (seldom used when getting data from a webservice)
  • No default parsing
  • Type inference out of the box (sy string identifier to an int for example)
  • Can parse and fill an existing object
  • Custom date parsing on a case per case basis
  • Very concise syntax

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 :)

Doesn't compile with snapshot 4-12

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?

How do I instantiate a model directly from a string containing json?

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.

Doesn't compile on Linux OS

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'

Support optional data for custom models

Hi! In some cases optional vars 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 _'.

Array of enums

Having trouble of parsing an array of enums.

var weekdays: [WeekDay]?

Response:

{
  "weekdays": [1, 3]
}

Parse:

self.weekdays <-- json["weekdays"]

Outcome is nil. :/

Release 3.0.3 not available on master

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 by ws

Value of type 'JSON' has no member 'collection'

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.