1. Simpler APIs, Omit unneccessary words.
helloString.stringByAppendingString("world")
helloString.appending("world")
let blue = UIColor.blueColor()
let blue = UIColor.blue
NSBundle.mainBundle()
Bundle.main
numbers.maxElement()
numbers.max()
animals.insert("Koala", atIndex: 0)
animals.insert("Koala", at: 0)
2. GCD and Core Graphics.
let queue = dispatch_queue_create("com.test.myqueue", nil)
dispatch_async(queue) {
print("Hello World")
}
DispatchQueue(label: "com.test.myqueue").async {
print("Hello World")
}
CGContextSetLineWidth(context, strokeWidth)
context.setLineWidth(strokeWidth)
CGContextDrawPath(context, kCGPathStroke)
context.drawPath(using: .stroke)
3. Capitalization on Enumeration Cases
UIStatusBarStyle.LightContent
UIStatusBarStyle.lightContent
doneButton.setTitleColor(.LightGrayColor(), for: .Disabled)
doneButton.setTitleColor(.lightGray, for: .disabled)
4. Function Changes
override func numberOfSectionsInTableView(tableView: UITableView) -> Int
override func numberOfSections(in tableView: UITableView) -> Int
dismissViewControllerAnimated(true, completion: nil)
dismiss(animated: true)
override func viewWillAppear(animated: Bool)
override func viewWillAppear(_ animated: Bool)
5. Completion Block
Use @escaping
before the completion blocks.
6. Use _
where ever required in the function declaration
func tappedOnView(view: UIView) {
view.endEditing(true)
}
self.tappedOnView(view: view)
func tappedOnView(_ view: UIView) {
view.endEditing(true)
}
self.tappedOnView(view)
func tapped(on view: UIView) {
}
self.tapped(on: view)