Swift 5.0
let userInput = "18"
var age = Int(userInput)
if age != nil {
print("Your age is + \(String(describing: age!))")
}
let userInput = "18"
var age = Int(userInput)
if age != nil {
print("Your age is + \(String(describing: age!))")
}
2019-08-15
2017年后新版Swift有部分修改:
let lbl = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 100));
let btn = UIButton(frame: CGRect(x: 100, y: 100, width: 200, height: 80));
btn.setTitleColor(UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1.0), for: .normal);
btn.setTitle("Click me!", for: .normal);
let lbl = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 100));
let btn = UIButton(frame: CGRect(x: 100, y: 100, width: 200, height: 80));
btn.setTitleColor(UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1.0), for: .normal);
btn.setTitle("Click me!", for: .normal);
2019-05-12
弃用++和--
// 反向循环
for i in (0 ... 10).reversed() {
print(i)
}
for i in (0 ..< 10).reversed() {
print(i)
}
// 反向循环
for i in (0 ... 10).reversed() {
print(i)
}
for i in (0 ..< 10).reversed() {
print(i)
}
2018-03-28