Skip to content

Instantly share code, notes, and snippets.

@isthisjoe
Last active August 29, 2015 14:07
Show Gist options
  • Save isthisjoe/b3112e6ce267d9fa06ab to your computer and use it in GitHub Desktop.
Save isthisjoe/b3112e6ce267d9fa06ab to your computer and use it in GitHub Desktop.
:: Swift iOS Version Checking ::
let iOS7 = floor(NSFoundationVersionNumber) <= floor(NSFoundationVersionNumber_iOS_7_1)
let iOS8 = floor(NSFoundationVersionNumber) > floor(NSFoundationVersionNumber_iOS_7_1)
:: Replace Magic Strings with Enumerations in Swift ::
enum SegueIdentifier: String {
case OtherScreenSegue1 = "otherScreenSegue1"
case OtherScreenSegue2 = "otherScreenSegue2"
case OtherScreenSegue3 = "otherScreenSegue3"
}
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if let identifier = SegueIdentifier.fromRaw(segue.identifier) {
switch identifier {
case .OtherScreenSegue1:
println("Going to other screen 1")
..
default:
println("Going somewhere else")
}
}
}
:: Print obj Type ::
let typeLongName = _stdlib_getDemangledTypeName(obj)
let tokens = split(typeLongName, { $0 == "." })
if let typeName = tokens.last {
println("Variable \(obj) is of Type \(typeName).")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment