Created
April 2, 2017 08:18
-
-
Save kateinoigakukun/1399c326b776351d823904ae4af66c3e to your computer and use it in GitHub Desktop.
目的完了してしまった #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 fruits: [Fruit] = [] | |
for i in 0..<0xff*MemoryLayout<Fruit>.size { | |
var n = i | |
var ptr = withUnsafePointer(to: &n) { UnsafeRawPointer($0) } | |
.bindMemory(to: Fruit.self, capacity: MemoryLayout<Fruit>.size) | |
if ptr.pointee.hashValue != n { break } | |
fruits.append(ptr.pointee) | |
} | |
fruits // [peach, apple, grape] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment