The use of square brackets [] objective-c understanding

Source: Internet
Author: User

1, used to inform an object what to do, that is, to notify the object to perform an action. In Objective-c, the meaning of "[]": They are used to inform an object what to do. The behavior of this notification object to perform an operation is called a "send message." For example: [shape draw]//This sentence means that the object shape is notified to perform draw, which means that the draw message is sent like the object shape. 2, create new Object 2.1 In order to create a new object, we need to send the corresponding new message to the class. Once the class has accepted and processed the new message, we will get an instance of the object that can be used. Example: ID shape[3]; Shape[0] = [Circle new]; When you send a new message to the Circle class, you create an object and assign the new object to Shape[0]. 2.2 uses a method in the class to return an instance of the class corresponding to the return value type of the method. NSData *now = [NSDate date];//indicates that a date message is sent to the NSDate class, the date method of the NSDate class creates a NSDate instance, initializes it to the current time, and then returns the starting address of the new object. 3, send a message to the superclass in class 3.1 For example @interface circle:shape@end//circle @implementation circle-(void) Setfillcolor: (Shapecolor) c {if (      c = = Kredcolor) {c = Kgreencolor; }[Super SETFILLCOLOR:C]; Sends a message to a super-class shape, and the superclass executes its Setfillcolor method. } @end//circle3.2 For example: self = [super init]; The function is to enable the superclass NSObject to complete its initialization work. And if you return a new object, you need to update self.

The use of square brackets [] objective-c understanding

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.