Skip to content

Instantly share code, notes, and snippets.

@cdl
Created June 18, 2015 03:57
Show Gist options
  • Save cdl/60f640ea2aa8f4b0d952 to your computer and use it in GitHub Desktop.
Save cdl/60f640ea2aa8f4b0d952 to your computer and use it in GitHub Desktop.
// view contains a label and a button - curious about lines 11 through 14
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!
// ...
@IBAction func didPressButton(sender: AnyObject) {
let date = NSDate()
// what's the difference between doing:
label.text = "Button pressed at \(date)"
// versus doing:
self.label.text = "Button pressed at \(date)"
}
}
@tillson
Copy link

tillson commented Jun 18, 2015

In Objective-C, self would be required to specify that it is a function of the View Controller. In Swift, it isn't necessary to start with self (They do the same thing, but the version without self is preferred).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment