Skip to content

Instantly share code, notes, and snippets.

@rileytestut
Created June 23, 2016 21:14
Show Gist options
  • Save rileytestut/56981c48f1dd5eb1b00effdac9e04472 to your computer and use it in GitHub Desktop.
Save rileytestut/56981c48f1dd5eb1b00effdac9e04472 to your computer and use it in GitHub Desktop.
Swift Tuple Casting
import Foundation
let string1: NSObject = NSString(string: "string1")
let string2: NSObject = NSString(string: "string2")
if let result = (string1, string2) as? (NSString, NSString)
{
print(result)
}
else
{
print("Failure")
}
// Prints: Failure
if let result = (string1, string2) as? (NSObject, NSObject)
{
print(result)
}
else
{
print("Failure")
}
// Prints: (string1, string2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment