Thanks Ole, that’s definitely nicer, I’ve updated my code! Still not exactly ergonomic though :-)
-Chris > On Jan 11, 2018, at 3:28 AM, Ole Begemann via swift-dev <swift-dev@swift.org> > wrote: > > > > In this particular example, you can use UInt8.init(ascii:) to make it a > little nicer (no need for the charToByte function): > > func hexToInt(_ c : UInt8) -> UInt8 { > switch c { > case UInt8(ascii: "0")...UInt8(ascii: "9"): > return c - UInt8(ascii: "0") > case UInt8(ascii: "a")...UInt8(ascii: "f"): > return c - UInt8(ascii: "a") + 10 > case UInt8(ascii: "A")...UInt8(ascii: "F"): > return c - UInt8(ascii: "A") + 10 > default: fatalError("invalid hexadecimal character") > } > }
_______________________________________________ swift-dev mailing list swift-dev@swift.org https://lists.swift.org/mailman/listinfo/swift-dev