Giter Club home page Giter Club logo

defaultcodable's People

Contributors

gonzalezreal 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

defaultcodable's Issues

Specifying default value (as literal) without implementing DefaultValueProvider protocol

So if I have to define a default value of 1.0, I can implement something like this:

public enum OneDouble: DefaultValueProvider {
    public static let `default`: Double = 1.0
}

And use it like this:

public class Estimate: Codable {
    @Default<OneDouble>
    public var fees: Double
}

For some reasons if I decide to change the value to 0.5, then I have to change it or add another enum:

public enum PointFiveDouble: DefaultValueProvider {
    public static let `default`: Double = 0.5
}

This looks cumbersome to me.

Is there any way to just use it like this:

public class Estimate: Codable {
    @Default(0.5)
    public var fees: Double
}

Is it possible to support more types of Codable?

Hi Guille

I love your open source projects, many of which are related to my work. Thank you for your work.

I'm working on a job implementing serialization and deserialization of NSFont and UIFont, aka Codable.

My code is like this:

    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        if let font = self.wrappedValue{
            let descriptorData = try? NSKeyedArchiver.archivedData(withRootObject: font.fontDescriptor, requiringSecureCoding: false) 
            try container.encode(descriptorData, forKey: .descriptor)
            try container.encode(font.pointSize, forKey: .pointSize)
            try container.encode(font.fontName, forKey: .fontName)
        }
    }

After I saw your open source project, I really liked this way of writing.
So I would like to give a suggestion, is there any Codable that supports more types. For example: the relevant support type of NSKeyedUnarchiver.

Also, after this type of parsing fails, a default value is returned.

Just an idea, if you have the same idea, we might as well give it a try.

M1 issue

Issue when building on Simulator on Apple Silicon.

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.