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
| extension Color { | |
| /// Return a random color | |
| static var random: Color { | |
| return Color( | |
| red: .random(in: 0...1), | |
| green: .random(in: 0...1), | |
| blue: .random(in: 0...1) | |
| ) | |
| } | |
| } |
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
| func encode<T>(var value: T) -> NSData { | |
| return withUnsafePointer(&value) { p in | |
| NSData(bytes: p, length: sizeofValue(value)) | |
| } | |
| } | |
| func decode<T>(data: NSData) -> T { | |
| let pointer = UnsafeMutablePointer<T>.alloc(sizeof(T.Type)) | |
| data.getBytes(pointer) | |