iOS Basic Learning II

Source: Internet
Author: User

1: @property @synthesize properties (similar to get set in Java)

The original implementation of the above class is this:#import   @interfacePhoto:nsobject {nsstring*caption; NSString*photographer; }   -(nsstring*) caption; -(nsstring*) photographer; - (void) Setcaption: (nsstring*) input; - (void) Setphotographer: (nsstring*) input; @endIf the property is used to achieve this:#import   @interfacePhoto:nsobject {nsstring*caption; NSString*photographer; } @property (retain) NSString*caption; @property (retain) NSString*photographer; @end@property's objective .-C to declare the compiler directive for the property. Inside the parentheses."retain"indicates the object that the setter needs to retain input. The other parts of this line specify the type and name of the property. Let's take a look at the implementation of this class:#import "Photo.h"   @implementationPhoto@synthesizecaption; @synthesizephotographer; - (void) Dealloc {[caption release];   [Photographer release];   [Super Dealloc]; }   @end@synthesize instructions are automatically generated by our setters and getters. So we just need to implement the Dealloc method of the class. Accessors are generated only when they are not. So you can be confident to use @synthesize to specify properties. And you can freely implement your own getter and setter. The compiler will find out for itself which method is not. 
View Code

iOS Basic Learning II

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.