Relative Content

Tag Archive for swiftgenerics

Why would Generic Type return something other than the none generic type?

extension Data { //generic method func value<T>(from byteOffset: Int, as: T) -> T { self.withUnsafeBytes { $0.load(fromByteOffset: byteOffset, as: T.self) } } //none-generic method func uint16Value(from byteOffset: Int) -> UInt16 { self.withUnsafeBytes { $0.load(fromByteOffset: byteOffset, as: UInt16.self) } } } When I output the following: let a = data.withUnsafeBytes { $0.load(fromByteOffset: 0, as: UInt16.self) } […]