buguibu / ios-notes-issues-lessons

Notes, issues and lessons about my iOS development experience
2 stars 0 forks source link

Swift Literal convertibles #15

Open buguibu opened 5 years ago

buguibu commented 5 years ago

Make a type expresable as a literal by conformin any of the existing literal convertibles protocols

E.g.:

extension CGRect: ExpressibleByArrayLiteral {
    public init(arrayLiteral elements: CGFloat...) {
        assert(elements.count == 4)
        let numbers = clip(elements, to: 4, defaultValue: 0)
        self.init(x: numbers[0], y: numbers[1], width:numbers[2], height:numbers[3])
    }
}

let rect: CGRect = [0, 0, 20, 20]