Only use @property to define a property speed, the subclass cannot be used directly with _speed, it needs to be written in the interface member variable list _speed

Source: Internet
Author: User

//Writing One:@interfaceperson:nsobject{} @property (Nonatomic, strong) NSString*name;@end@implementation Person@end//This applies to the general case, the compiler automatically generates the member variable _name, and the simplest notation, do not have to repeat the declaration. //two, in case of inheritance, expose the parent class member variable to the subclass :@interfaceperson:nsobject{NSString*_name;} @property (nonatomic, strong) NSString*name;@end@implementation Person@synthesizeName =_name;//This line is optional@end

@interfacetest:nsobject{//nsstring *_test; the disadvantage of not writing here is that a subclass inherits Test and will not be able to use the _test property directly } @property (nonatomic,copy) NSString*test;@end@implementationTest//@synthesize test = _test; The system did it for you, so you don't have to write .//@synthesize test = test_; If you think the front is unacceptable and you want to change it to the back, you have to write it .@endso write, the reason1, Concise2, external access is used. Test3, internal access with _test, System automatically generated

Writing one:
@interfacePersonNSObject{}@property(nonatomic,strong)NSString*name;@end@implementationPerson@end
This applies to the general case, the compiler automatically generates the member variable _name, and the simplest notation, do not have to repeat the declaration.

Two, in case of inheritance, expose the parent class member variable to the subclass:
@interface Person : NSObject{NSString *_name;}@property (nonatomic, strong) NSString *name;@end@implementation Person@synthesize name = _name;@end


Refusebt
Links: https://www.zhihu.com/question/22195598/answer/39593235
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

Only use @property to define a property speed, the subclass cannot be used directly with _speed, it needs to be written in the interface member variable list _speed

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.