Created
April 2, 2017 08:10
-
-
Save kateinoigakukun/c99904014d538b42e4a02bdd8126f539 to your computer and use it in GitHub Desktop.
switchはhashValueを見てるのか? #CodePiece
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Fruit { | |
case peach | |
case apple | |
case grape | |
} | |
var i = 3 | |
var emptyEnumPtr = withUnsafePointer(to: &i) { UnsafeRawPointer($0) } | |
.bindMemory(to: Fruit.self, capacity: MemoryLayout<Fruit>.size) | |
print(emptyEnumPtr.pointee) // 空 | |
print(emptyEnumPtr.pointee.hashValue) // 0 | |
switch emptyEnumPtr.pointee { | |
case .peach: print("peach") // peach | |
case .apple: print("apple") | |
case .grape: print("grape") | |
default: print("default") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment