Skip to content

Instantly share code, notes, and snippets.

@Pretz

Pretz/allOptions.swift

Last active Aug 29, 2015
Embed
What would you like to do?
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