Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardSwiftunsafeBitCast and pointersSingle-choice MCQ

You bind raw memory and read it as the wrong type. According to Swift's typed-memory model, what is the precise problem here even on a little-endian 64-bit platform where the read "succeeds"?

let p = UnsafeMutablePointer<Int>.allocate(capacity: 1) p.initialize(to: 0x4142) let b = UnsafeRawPointer(p).load(as: UInt8.self) // observed 0x42 print(b)