Giter Club home page Giter Club logo

Comments (3)

evermeer avatar evermeer commented on June 26, 2024

EVObject itself does not have any properties. You would need a container objects like you see in the code below. Besides that the root is an object with a data property and not an array.
You can find sample code here:

class myData: EVObject {
   var data: [myItem]
}

class myItem: EVObject {
   var someField: String?
}

Alamofire.request(.GET, URL)
                .responseObject { (request: NSURLRequest?, HTTPURLResponse: NSHTTPURLResponse?, response: Result< myData, NSError>) in
 // Do something with the response
}

from alamofirejsontoobjects.

daniaDlbani avatar daniaDlbani commented on June 26, 2024

thanks for the fast reply, I am not using EVObject directly I mean a subclass of it, although the data object is in all API responses so in this case I should incapsulate all My model to have super model with data property

from alamofirejsontoobjects.

evermeer avatar evermeer commented on June 26, 2024

Yes, And you only need 1 super model for the data property if you are using a base class for that. You do have to implement the getSpecificType method in that base class. You can find sample code for that here: https://github.com/evermeer/EVReflection/blob/master/EVReflection/EVReflectionTests/EVRelfectionEnheritanceTests.swift#L83

An other way to do this is by using generics. I think it's actueally a bit nicer. Sample code for that can be found here: https://github.com/evermeer/EVReflection/blob/master/EVReflection/EVReflectionTests/EVReflectionWorkaroundSwiftGenericsTests.swift#L97
And here is the test for that: https://github.com/evermeer/EVReflection/blob/master/EVReflection/EVReflectionTests/EVReflectionWorkaroundSwiftGenericsTests.swift#L59
And here is a nice sample code where the object is using generics but also the service call is created using generics: https://github.com/evermeer/AlamofireJsonToObjects/blob/master/AlamofireJsonToObjectsTests/NestedGenericsIssue25.swift#L25

from alamofirejsontoobjects.

Related Issues (20)

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.