Skip to content

Instantly share code, notes, and snippets.

@kateinoigakukun
Created April 2, 2017 07:52
Show Gist options
  • Save kateinoigakukun/35c8cceba801e9f1ea447ba61ad626c1 to your computer and use it in GitHub Desktop.
Save kateinoigakukun/35c8cceba801e9f1ea447ba61ad626c1 to your computer and use it in GitHub Desktop.
ほ~ #CodePiece
enum Fruit {
case peach
case apple
case grape
}
var aPeach = Fruit.peach
let aPeachPtr = withUnsafePointer(to: &aPeach) { UnsafeRawPointer($0) }
.bindMemory(to: Int.self, capacity: MemoryLayout<Int>.size)
print(aPeachPtr.pointee) // 0
var anApple = Fruit.apple
let anApplePtr = withUnsafePointer(to: &anApple) { UnsafeRawPointer($0) }
.bindMemory(to: Int.self, capacity: MemoryLayout<Int>.size)
print(anApplePtr.pointee) // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment