Giter Club home page Giter Club logo

codablealamofire's People

Contributors

danielsaidi avatar otbivnoe 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codablealamofire's Issues

Realm!

Can model structure with Object & Decodable?

Object: This Realm object.

JSONDecoder.dateDecodingStrategy not working for custom format

When using this DateFormatter separately, I can successfully deserialize date string with it:

extension DateFormatter {
    static let apiDateFormatter: DateFormatter = {
        let formatter = DateFormatter()
        //2019-08-05T08:41:06.590Z
        formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
        return formatter
    }()
}

If I use the same formatter when calling .responeDecodableObject(decoder: decoder), model properties (of Date type) are set to nil.

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .formatted(.apiDateFormatter)

Alamofire.request(url, method: method, parameters: parameters, encoding: encoding, headers: headers)
    .responseDecodableObject(decoder: decoder) { (response: DataResponse<T>) in
        let data = response.data
}

Is there any more setup that I am not aware of? Thanks

Alamofire 5 compatibiliy

Hello,

First of all thanks for such useful library.

It seems Alamofire 5.0.0-rc.3 is API stable now. Is there a way/branch to use that with CodableAlamofire? without forking?

Best

`GenericCache(0x1016d3d40): cyclic metadata dependency detected, aborting` when work with generic decodable type

Swift 4 & Xcode 9.0 on mac OS High Sierra

Where the issue accurs:

...alamofireRequest.responseDecodableObject(
    queue: nil, 
    keyPath: nil, 
    decoder: JSONDecoder()) { 
        (resp: DataResponse<GenralResponse<FlexibleValue>>) in
        logger.verbose(resp)
}

Related Types

// FlexibleValue is for decoding the flexible part of response JSON.

struct FlexibleValue: Decodable {
    var role: [String]
}

// GeneralResponse<T> is the designed to decode general response from back-end, with a hosted type T, which is decodable too.

struct GeneralResponse<T: Decodable>: Decodable  {
    struct Head: Decodable {
        let version: String
        let msgtype: String
        let interface: String
        let remark: String
    }
    struct Body: Decodable {
        let ret: String
        let retcode: String
        let retinfo: String
        let data: T?
    }
    let head: Head
    let body: Body
}

Dependency Specification prevents Updates

The Alamofire dependency is specified in such a manner that users of this pod are locked to a specific minor version. As Alamofire follows sematic versioning (see Alamofire/Changelog), locking this dependency to a major version is all that should be required.

Is it possible for

s.dependency 'Alamofire', '~> 5.0.0-rc.3'

to be replaced with

s.dependency 'Alamofire', '~> 5.0'

JSON property sometimes is a numeric value and sometimes a string value

Hi,

I have a special case, I have a JSON response which sometimes returns a numeric value and sometimes a string value for the same key. Is there any way to handle such a JSON response.

I know, that this isn't a good idea in general, but I don't have access to the server backend ๐Ÿ˜‰.

Cannot convert value of type 'HTTPHeaders' (aka 'Dictionary<String, String>') to expected argument type 'DispatchQueue?

    var id:        String
    var owner_id:  String
    var name:      String
    var active:    Bool?
    var share:     Bool?
    var date:      Int?
    var duration:  Int
    
    typealias DownloadComplete = () -> ()
}

extension ActiveChannelHangouts {
    static func from(json: String, using encoding: String.Encoding = .utf8) -> ActiveChannelHangouts? {
        guard let data = json.data(using: encoding) else { return nil }
        return ActiveChannelHangouts.from(data: data)
    }
    
    static func from(data: Data) -> ActiveChannelHangouts? {
        let decoder = JSONDecoder()
        do {
            return try decoder.decode(ActiveChannelHangouts.self, from: data)
        } catch  {
            print(error.localizedDescription)
            return nil
        }
    }
    
    var jsonData: Data? {
        let encoder = JSONEncoder()
        do {
            return try encoder.encode(self)
        } catch {
            print(error.localizedDescription)
            return nil
        }
    }
    
    var jsonString: String? {
        guard let data = self.jsonData else { return nil }
        return String(data: data, encoding: .utf8)
    }
    
}

extension ActiveChannelHangouts {
    enum CodingKeys: String, CodingKey {
        case id       = "id"
        case ownerId  = "ownerId"
        case name     = "name"
        case active   = "active"
        case share    = "share"
        case date     = "date"
        case duration = "duration"
    }
}

// from my APIClient struct trying to call this method 
func responseDecodableObject<T: Decodable>(url: String, queue: DispatchQueue? = nil,
                                               keyPath: String? = nil,
                                               decoder: JSONDecoder = JSONDecoder(),
                                               completionHandler: @escaping (DataResponse<T>) -> Void) {
        if !PerfectLocalAuth.sessionid.isEmpty {
            Alamofire.request(url).responseDecodableObject(queue: PerfectLocalAuth.setHeaders(), keyPath: keyPath, decoder: decoder) {
                (response: DataResponse<[T]>) in
                let repo = response.result.value
                print(repo)
            }
            
        }
    }

i am trying to create one func that can be handle for all my fetch request but i go this error
Cannot convert value of type 'HTTPHeaders' (aka 'Dictionary<String, String>') to expected argument type 'DispatchQueue?

keyPath performance issues

Really handy library, thanks for making it.

I'm wondering if you think the responseDecodableObject[keyPath: ...] is a good call. There's going to be performance hit deserializing to json then serializing back to data then deserializing to codable object.

Users might not look under the hood and see this. Isn't better they just make a container object or writing a customer coder method? Also asking for myself really.

Best,

Moya

Hi!
It will be nice to have something like Codable, but for Moya :)

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.