Retain strong and copy discussion, there are recommended children's shoes please leave a message

Source: Internet
Author: User

To summarize my understanding:
Strong weak is an arc introduced, strong is equivalent to retain, but for some types, such as NSString, the use of strong is equivalent to using the copy
So directly with strong can directly deal with the situation of retain and strong.
Weak is equivalent to assign, but a bit more than the latter: when the object is killed, the weak reference is set to nil, and no message to nil causes a crash

Otherwise the weak is referenced as a wild pointer and there is a problem


Here it is said that strong has copy function is wrong oh. Experimental examples

@interface Appdelegate:uiresponder <UIApplicationDelegate>
{
NSString *retainstr;
NSString *copstr;
NSString *strongstr;
}

@property (Retain, nonatomic) NSString *retainstr;
@property (Strong, nonatomic) NSString *strongstr;
@property (copy, nonatomic) NSString *copstr;

@end

nsmutablestring *newstr = [nsmutablestring stringwithformat:@ "ABCD"];
Self.retainstr = Newstr;
Self.strongstr = Newstr;
Self.copstr = Newstr;

[Newstr appendstring:@ "123"];

NSLog (@ "Retain sting:%@", self.retainstr);
NSLog (@ "Strong string:%@", SELF.STRONGSTR);
NSLog (@ "Copy string:%@", SELF.COPSTR);

Output Result:
2014-05-02 13:31:17.660 testmultiplethreaddownload[552:60b] retain sting:abcd123
2014-05-02 13:31:17.662 testmultiplethreaddownload[552:60b] Strong string:abcd123
2014-05-02 13:31:17.663 testmultiplethreaddownload[552:60b] Copy STRING:ABCD

Retain strong and copy discussion, there are recommended children's shoes please leave a message

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.