Skip to content

Instantly share code, notes, and snippets.

@Pretz
Last active August 29, 2015 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pretz/128da1f9d5aea4db1aef to your computer and use it in GitHub Desktop.
Save Pretz/128da1f9d5aea4db1aef to your computer and use it in GitHub Desktop.
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