Saturday, July 8, 2017

How to: Basic of XCode Methods & Functions in Objective-C

Why ObjC?

Cause we're oldskool! :D


When we start to code, what we need to do is write methods on top of the already available delegates (namely the View Lifecycles delegates like viewDidLoad or viewDidLayoutSubviews). A typical method that we quickly create is IBActions. These are automatically created when you drag an outlet in Storyboard to your header file.

-(IBAction)aButtonWasClicked:(id)sender {
  // your button was clicked by user

The aButtonWasClicked: is the name of the method. Note that I include the semicolon at the end. This indicates there is a parameter to be supplied to the method. So if you want to call this method elsewhere programatically, you need to write: