Objective-c Object-Oriented Foundation

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.