Swift Experimentation

var hello: String = "Hello World"
var hello:String = "Hello, World"
hello = 1
print(str)
func printInfo (value: Any){
let t = type(of: value)
print("\(value) of type \(t)" )
}var hello:String = "Hello, World"
hello = 1
print(str)
var number = 5
printInfo(value: number)
5 of type Int
func printInfo (value: Any){}
var number = 5
printInfo(value: number)
func printInfo (_ value: Any){}
printInfo(number)
func printInfo (value: String)
var number = 5
printInfo(value: number)
const funFunction = (a,b) => {
console.log(a + b.toUpperCase())
}
func funFunction(_ a: String, _ b:String){
let b = (b.uppercased())
print (a + b)
}
funFunction("hello", 1)
error: eligible-.playground:14:22: error: cannot convert value of type 'Int' to expected argument type 'String'
funFunction("hello", 1)

UInt8 (min: 0, max: 255)

UInt16( min: 0, max: 65535)

UInt32(min: 0, max: 4294967295)

UInt64(min: 0, max: 18446744073709551615)

let negativeForty:Int = -40
let number1: UInt16 = 120
let number2: UInt8 = 4
let outputNum = (number1+number2)
print(outputNum)
=> overloads for '+' exist with these partially matching parameter lists: (UInt16, UInt16)
UInt16(number2)
var number1: UInt16 = 120
var number2: UInt8 = 4
//adding number 1 to convert number 2 to 16 bit from 8
var outputNum = (number1+UInt16(number2))
print(outputNum)

=> 124

Tuples

let chance = ("dog", false, 3)
let (animal, good, age) = chance
print(("\(good)"))
=> false
//the value of false is automatically linked up to the value of 'good' in the tupple
func recipe(ingredientsCt:Int, mainIngredient: String ){
let recipe = (ingredientsCt, mainIngredient)
print("You're going to cook \(recipe.0) portion of \(recipe.1)")
}
recipe(ingredientsCt: 1, mainIngredient: "Rice")

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store