Last active
August 29, 2015 14:16
-
-
Save Pretz/128da1f9d5aea4db1aef to your computer and use it in GitHub Desktop.
This file contains 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 UIKit | |
func allOptions<T: RawOptionSetType where T.RawValue == UInt>(optionSet: T) -> [T] { | |
var options = [T]() | |
var mask: UInt = 1 | |
while mask != 0 { | |
if let newOption = T(rawValue: mask) where (optionSet & newOption) == newOption { | |
options.append(newOption) | |
} | |
mask <<= 1 | |
} | |
return options | |
} | |
let optionSet: UIViewAnimationOptions = .LayoutSubviews | .AllowAnimatedContent | .TransitionFlipFromRight | |
for option in allOptions(optionSet) { | |
typealias T = UIViewAnimationOptions | |
switch option { | |
case T.LayoutSubviews: | |
println("layout subviews") | |
case T.TransitionFlipFromLeft: | |
println("not reached") | |
case T.AllowAnimatedContent: | |
println("allow animated content") | |
default: | |
println("this prints once: \(option)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment