The difference between declaring a variable in a "go" ios,objective_c with a @interface and @property way

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="word-wrap: break-word; color: #333333;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;">Original: http://blog.csdn.net/ganlijianstyle/article/details/7924446</span></span></span></p></p><p><p><span style="word-wrap: break-word; color: #333333;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;">1. In the parentheses of @interface: nsobject{}, of course nsobject refers to a parent class, which can be other.</span></span></span></p></p><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;">The form is as Follows:</span></span></p></p><p><span style="word-wrap: break-word; color: #333333;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px; color: #0000ff;">@interface<span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;">Gcturnbasedmatchhelper:nsobject {<br style="word-wrap: break-word; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap:break-word; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;">& nbsp   BOOL GAMECENTERAVAILABLE;<br style="word-wrap:break-word; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; "><span style="word-wrap:break-word; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;">     BOOL USERAUTHENTICATED;<br style="word-wrap:break-word; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; "><span style="color: #444444; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;"> }<br style="word-wrap:break-word; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; "><br style="word-wrap:break-word; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; "></span></span></span></span></span></span></span></span></span></p><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><p style="word-wrap:break-word; margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:25px; text-align:left; "><span style="word-wrap:break-word; color: #333333;"><span style="font-family:verdana,arial,helvetica, sans-serif; word-wrap:break-word; ">2. the other is to use @property to define a variable directly after the @interface: nsobject{} Parenthesis. </span></span></p></p><p><span style="word-wrap: break-word; color: #333333;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px; color: #0000ff;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #444444; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;">< Span style= "word-wrap:break-word; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; Color: #008080; " >1<span style="color: #444444; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;">   @property (assign, <span style="word-wrap:break-word; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px; Color: #0000ff; ">readonly<span style="color: #444444; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;"> ) BOOL GAMECENTERAVAILABLE;<br style="word-wrap:break-word; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; "><br style="word-wrap:break-word; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; "></span></span></span></span></span></span></span></span></span></span></span></span></p><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;">You'll find that once you've defined the variables in the @interface, it's common to repeat the same variables in the @property.</span></span></p></p><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;">The result may be this:</span></span></p></p><p><span style="word-wrap: break-word; color: #333333;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px; color: #0000ff;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px; color: #008080;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px; color: #0000ff;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #b00000; word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><br style="word-wrap: break-word;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px; color: #0000ff;">@interface<span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;">Gcturnbasedmatchhelper:nsobject {<br style="word-wrap: break-word; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;">BOOL gamecenteravailable;<br style="word-wrap: break-word; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;">BOOL userauthenticated;<br style="word-wrap: break-word; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap:break-word; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;">}< BR style= "word-wrap:break-word; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; " ><span style="color: #444444; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;"> @property (assign, <span style="word-wrap:break-word; font-family:tahoma, ' Microsoft yahei ', simsun; font-size: 14px; line-height:21px; Color: #0000ff; ">readonly<span style="color: #444444; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;"> ) BOOL GAMECENTERAVAILABLE;<br style="word-wrap:break-word; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; "><br style="word-wrap:break-word; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; "></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><p style="word-wrap:break-word; margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:25px; text-align:left; "><span style="word-wrap:break-word; color: #333333;"><span style="font-family:verdana,arial,helvetica, sans-serif; word-wrap:break-word; "> and you can define variables individually in @interface without @property definitions, or you can just define them with @property, not in @interface, and of course @property to define them, usually in. m files with @ Synthsize to synthesize the corresponding Setter,getter method. Otherwise you will get a warning. Of course @synthsize is optional, but Apple recommended, no consequences, I have not tried, interested in Children's shoes can try. </span></span></p></p><p><span style="word-wrap: break-word; color: #333333;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px; color: #0000ff;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px; color: #008080;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px; color: #0000ff;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #b00000; word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px; color: #0000ff;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="word-wrap: break-word; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 21px;"><span style="color: #444444; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;">< Span style= "word-wrap:break-word; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; " ><span style="word-wrap:break-word; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;"> <span style="color: #444444; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;">< Span style= "word-wrap:break-word; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; Color: #0000ff; " ><span style="color: #444444; font-family:tahoma, ' Microsoft yahei ', simsun; font-size:14px; line-height:21px;"> <br style="word-wrap:break-word; Color: #444444; font-family:tahoma, ' Microsoft Yahei ', simsun; font-size:14px; line-height:21px; "></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;">What is the difference between these two ways?</span></span></p></p><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;">1. If you define variables only in @interface, the variables you define can only be accessed in the current class, not in other classes, and variables declared with @property may be accessed externally.</span></span></p></p><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><p style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: #444444; font-family: Tahoma,‘Microsoft Yahei‘,Simsun; font-size: 14px; line-height: 25px; text-align: left;"><span style="word-wrap: break-word; color: #333333;"><span style="font-family: verdana,Arial,Helvetica,sans-serif; word-wrap: break-word;">2. Using @property to declare variables, you can use the "SELF. variable name" method to read and write Variables. And the way to use @interface is not possible.</span></span></p></p><p><p>The difference between declaring a variable in a "go" ios,objective_c with a @interface and @property way</p></p></span>

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.