IOS Set method

Source: Internet
Author: User

In order for the member variables of the class to be properly accessed by the external, we need to set the sets and get methods.

[OBJC]View Plaincopy < param name= "wmode" value= "Transparent" >
    1. @property (nonatomic,retain)nsstring *test1;
    2. @property (nonatomic,copy)nsstring *test2;


The properties of a member variable are different (retain,copy) relative to the Set method:

[OBJC]View Plaincopy
    1. @implementation Secondviewcontroller
    2. -(void) settest1: (nsstring *) test//retain
    3. {
    4. //test needs to be retain first, and test is released to nil when self-assignment
    5. [Test retain];
    6. if (_test1! = nil) {
    7. [_test1 release];
    8. }
    9. //Direct release No need to judge is also possible, iOS in the release operation of Nil is legal
    10. //[_test1 release];
    11. _test1 = test;
    12. }
    13. -(void) Settest2: (NSString *) test//copy
    14. {
    15. if (_test2! = nil) {
    16. [_test2 release];
    17. }
    18. //can also not be judged
    19. //[_test2 release];
    20. _test2 = [test copy];
    21. }

IOS Set method

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.