ExpressibleByTupleLiteral

For example

struct FinderTag : ExpressibleByTupleLiteral {
    let name: String
    let color: Color
    init(tupleLiteral: (String, Color)) {
        name = tupleLiteral.0
        color = tupleLiteral.1
    }
}

enum Color: Int {
        case none
        case gray
        case green
        case purple
        case blue
        case yellow
        case red
        case orange
}
let tag: FinderTag = ("tagWithRed", .red)
let tags: [FinderTag] = [("tagWithRed", .red), ("tagWithYellow", .yellow)]
1 Like

You can use this code without using tuples, which is much more clear than yours I think:

struct FinderTag {
    let name: String
    let color: Color
    init(_ name: String, _ color: Color)) {
        self.name = name
        self.color = color
    }
}

enum Color: Int {
        case none
        case gray
        case green
        case purple
        case blue
        case yellow
        case red
        case orange
}
let tag: FinderTag = .init("tagWithRed", .red)
let tags: [FinderTag] = [.init("tagWithRed", .red), .init("tagWithYellow", .yellow)]
1 Like
Terms of Service

Privacy Policy

Cookie Policy