Created
March 15, 2013 18:28
-
-
Save TiernanKennedy/5171953 to your computer and use it in GitHub Desktop.
A method with one argument (parameter) and a return type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To create a method that accepts an integer (int) and returns that integer squared | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// first we delare our integer | |
int myInt = 666 | |
// now look what's happening here - it will print "666 squared is 443556" | |
// how does this happen? | |
// When we send myInt to our method - it jumps out of viewDidLoad and into our method | |
// it then will print out "You passed in the value" - then it will square our int and return it to the ViewDidLoad | |
NSLog(@"%i squared is %i", myInt, [self myMethod:(myInt)]; | |
} | |
-(int) myMethod:(int)funBoy{ | |
// we print the value that was passed to us from viewDidLoad | |
NSLog(@"You passed in the value %i", funBoy); | |
// we then multiply this value by itself to get the square | |
int returnInt = funBoy * funBoy; | |
// we then return our integer | |
// this effectively sends back that value to viewDidLoad | |
// our method in viewDidLoad will now be equal to that value | |
// i.e. [self myMethod:(myInt)] == myInt * myInt | |
return returnInt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment