Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Nested model parsing #2

Closed
alhafoudh opened this issue Sep 26, 2014 · 1 comment
Closed

Nested model parsing #2

alhafoudh opened this issue Sep 26, 2014 · 1 comment

Comments

@alhafoudh
Copy link

I am trying to get nested model parsing to work, but without any success. The Xcode keeps hanging and crashing. :(

I tried to move the mapping block to separate class method like:

extension Location: JSONDecodable {
  static func create(lat: Double)(lon: Double) -> Location {
    return Location(lat: lat, lon: lon)
  }  

public static func mapper(d: JSONObject) -> Location? {
    return Location.create
        <^> d <|  "lat"
        <*> d <|  "lon"
  }
}

and then in parent model trying to parse it:

extension Post: JSONDecodable {
  static func create(id: Int)(subject: String)(location: Location) -> Post2 {
    return Post2(id: id, subject: subject, location: location)
  }

  public static func mapper(d: JSONObject) -> Post2? {
    return Post2.create
        <^> d <|  "id"
        <*> d <|  "subject"
        <*> (d <| "location") >>> Location.mapper
  }
}

after that when I hit Build, the SourceKit crashes, switfc compiler hangs and after a while, Xcode too (using Xcode 6.0.1)

@alhafoudh
Copy link
Author

Actually I found a bug in my code. It works as I wrote it here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant