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
import Foundation | |
typealias Mask = UInt64 | |
enum Category: UInt8 { | |
case A | |
case B | |
case C | |
case D | |
case E |
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
// The following shows that Equatable for NSObject is not necessarily safe | |
// for Swift classes that extend NSObject and override Equatable. | |
// Reference: http://natashatherobot.com/swift-equatable-with-optionals/ | |
class TitleNSObject: NSObject { | |
var title: String = "" | |
init(title: String) { | |
super.init() | |
self.title = title |
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
// Note: This requires libextobjc: https://github.com/jspahrsummers/libextobjc | |
inline static void propertyChangeObject(NSObject *object, NSString *keypath, void (^block)()) { | |
[object willChangeValueForKey: keypath]; | |
block(); | |
[object didChangeValueForKey: keypath]; | |
} | |
#define propertyChange(__KEY, block) propertyChangeObject(self, @keypath(self.__KEY), block) | |
#define propertyChange2(keypath, block) propertyChangeObject(self, keypath, block) |
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 Reindeer: Int { | |
case Dasher, Dancer, Prancer, Vixen, Comet, Cupid, Donner, Blitzen, Rudolph | |
static var allValues: [Reindeer] { | |
return allValuesGenerator({ Reindeer(rawValue: $0) }) | |
} | |
} | |
func allValuesGenerator<T>(fromValue: Int -> T?) -> [T] { | |
return Array( |
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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<playground version='3.0' sdk='macosx'> | |
<sections> | |
<code source-file-name='section-1.swift'/> | |
<code source-file-name='section-2.swift'/> | |
<code source-file-name='custom-filename.swift'/> | |
</sections> | |
<timeline fileName='timeline.xctimeline'/> | |
</playground> |