At present, mobile development in the buzz, today at home to learn the recent "Objective-c Basic Tutorial", the initial feeling objective-c and. Net difference is very big, in order to better understand objective-c, will take note of the form of learning knowledge points, easy to access.
In the Objective-c class is divided into two parts: Declaration and implementation, declaring the use of keyword @interface, implementation using keyword @implementation, the @ symbol can be understood as a C language extension, in the. NET is using the class keyword, as follows:
@interfaceperson:nsobject{@privateNSString*FirstName; NSString*LastName;}- (void) Setfirstname: (nsstring*) FName;- (void) Setlastname: (nsstring*) LName;-(nsstring*) description;+ (nsstring*) Breath;@end@implementation Person-(void) Setfirstname: (NSString *) fname{ Self->firstname =FName;}-(void) Setlastname: (NSString *) lname{ Self->lastname =LName;}-(nsstring*) description{return[[Self->firstname stringbyappendingstring:@" "] Stringbyappendingstring:self->lastName];}+ (nsstring*) breath{return @"Air";}@end
The observation code draws the following points:
1. Each method is preceded by a "+" or "-" symbol,+ means that the method is called by the class as a class method, which means that the method is called by an instance method as an instance.
2. the Self keyword table references the instance object itself, similar to the This keyword feature in. net.
3. NSObject is a base class in Objective-c, and custom classes recommend inheriting NSObject.
4. Description method inheritance and NSObject, overridden in person, in objective-c if the instance object is used directly, the default call to the description method is equivalent. The ToString in net.
5. In Objective-c, the method is called between a pair of parentheses, in the form of: [instance method:parameter parameter ...]
Objective-c Object-Oriented Foundation