let str:String = "Hello"
let str = "Hello"
//On the right side"Hello"Is a String type, so str is implicitly a String type
let color:UIColor = UIColor.red
let color:UIColor = .red
//Since UIColor is explicitly declared on the left side, UIColor on the right side can be omitted.
UIView.animate(withDuration: 1, delay 1,
options: UIView.AnimationOptions.curveEaseIn,
animations: { }, completion: nil)
UIView.animate(withDuration: 1, delay 1,
options: .curveEaseIn,
animations: { }, completion: nil)
//Since the argument type is UIView's AnimationOptions, it can be omitted.
(reference) https://t.co/j5Yq9fIrQO?amp=1
let add = (num1 ?? 0 as Int) + (num2 ?? 0 as Int) + (num3 ?? 0 as Int)
//It is faster to specify the type
let add1 = num1 ?? 0 as Int
let add2 = num2 ?? 0 as Int
let add3 = num3 ?? 0 as Int
let sum = add1 + add2 + add3
//It is easier to unwrap it first, or to decompose it for complicated expressions before calculating it.
Recommended Posts