UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Struct with Color atribute to decode

Forums > SwiftUI

How to decode a Color atribute?

I want to use it to personalize Color atribute in Swift UI...

struct Loja : Identifiable, Codable {
    var id = UUID()
    var lojaId : Int
    var nome : String
    var logomarca : String
    var imagemcapa : String
//    var cor : Color (this)
    var telefone : String
    var frete : Double?
    var ordenacao : Int

    enum CodingKeys: String, CodingKey {
        case lojaId, nome, logomarca, imagemcapa, telefone, frete, ordenacao
    }

3      

Color is not Codable. You have to change it RGB and save that the codable How to read the red, green, blue, and alpha color components from a UIColor.

However if the Color are in Asset.xcassets then you can refer to them as String

Color("yourColor")

4      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.