Skip to content

Instantly share code, notes, and snippets.

@benstone1
Created September 21, 2017 22:12
Show Gist options
  • Save benstone1/83f719a700180032ae949036c7df3dea to your computer and use it in GitHub Desktop.
Save benstone1/83f719a700180032ae949036c7df3dea to your computer and use it in GitHub Desktop.
let testNum: Double = 3.0
let numAsInt = Int(testNum)
let numConvertedBackToDouble = Double(numAsInt)
numConvertedBackToDouble == testNum
var myPoint: (Double, Double)
myPoint = (4,2)
switch myPoint {
case (0..<Double.infinity, 0..<Double.infinity):
print("Q1")
case let (x,y) where x < 0 && abs(y) == y:
print("Q1")
case (-Double.infinity..<0, 0..<Double.infinity):
print("Q2")
case let (a,b) where abs(a) != a && abs(b) == b:
print(a)
print("Q2")
default:
break
}
let pAndQ: (Bool, Bool)
pAndQ = (true, false)
switch pAndQ {
case (true, false):
print("|| works")
case (false, true):
print("|| works")
case (true, true):
print("|| and && both work")
case (false, false):
print("Neither works")
}
let pAndQAndR: (Bool, Bool, Bool) = (true, false, true)
switch pAndQAndR {
case (true, true, true):
print("And and Or work")
case (false, false, false):
print("Nothing works")
default:
print("Or works")
}
let firstName = "Ph"
let lastName: String
if firstName == "Peter" {
lastName = "Gabriel"
} else if firstName == "Phil" {
lastName = "Collins"
} else {
lastName = "Unknown"
}
let fullName = firstName + " " + lastName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment