Giter Site home page Giter Site logo

Comments (4)

fwaddle avatar fwaddle commented on September 18, 2024

I modified the code to get it to work but it doesn't matter as I still can't use the colour asset stuff with old versions of ios. It works fine if you do it in code but not if you use storyboards to set the colours. Bugger!

Thanks anyway.

from colorassetcatalog.

samrayner avatar samrayner commented on September 18, 2024

Odd, I wouldn't expect those component values to be Strings! They should always be numerical (without quotes) in the JSON. Did you modify or generate that JSON manually?

from colorassetcatalog.

adamwidera1978 avatar adamwidera1978 commented on September 18, 2024

To reproduce, use the latest version of the Xcode. It saves the values of the colours as strings instead of doubles.

The decoding failure relates to this issue inside swift:
https://bugs.swift.org/browse/SR-5249

Modification to the ColorAssetCatalog.swift that would make it usable again is:

extension ColorAsset.Color {

struct Components: Decodable {
    var alpha: CGFloat = 1
    var red: CGFloat = 0
    var green: CGFloat = 0
    var blue: CGFloat = 0

    var white: CGFloat? {
        didSet {
            guard let white = white else { return }
            red = white
            green = white
            blue = white
        }
    }
    
    enum CodingKeys: String, CodingKey {
        case alpha
        case red
        case green
        case blue
    }
    
    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        alpha = CGFloat(Double(try values.decode(String.self, forKey: .alpha))!)
        red = CGFloat(Double(try values.decode(String.self, forKey: .red))!)
        green = CGFloat(Double(try values.decode(String.self, forKey: .green))!)
        blue = CGFloat(Double(try values.decode(String.self, forKey: .blue))!)
    }
}

}

from colorassetcatalog.

samrayner avatar samrayner commented on September 18, 2024

Thank you @adamwidera1978!

I've made the change. Will publish a new version to Cocoapods when I get a chance later.

2b8a06c

from colorassetcatalog.

Related Issues (9)

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.