Objective-C Basic

时间:2024-09-20 12:35:38

1. Methods and Messages

a) class method - call it by sending a message to the class itself
 b) instance method - call it by sending a message to an instance of the class
 
An Objective-C method’s name must contain exactly as many colons as the method
takes parameters, and, the parameter name must end with a colon

c) Calling a Method
 eg:
 NSString* s = @"Hello, world!";
 NSString* s2 = [s uppercaseString];
 <=>
 NSString* s2 = [@"Hello, world!" uppercaseString];
 
 //If a method takes no parameters, then its name contains no colons
 //If a method takes two or more parameters, its name contains that number of colons
 eg:
 [someObject hereAreThreeStrings: @"string1" : @"string2" : @"string3"];