iOS copy and retain strings

Source: Internet
Author: User

1@property (Retain, nonatomic) NSString *Retainstr;2@property (copy, nonatomic) NSString *Copystr;3 4  5 6@property (Retain, nonatomic) nsmutablestring *Retainmstr;7@property (copy, nonatomic) nsmutablestring *Copymstr;8 9  Ten  One The implementation code is as follows: A  -nsmutablestring *mstr = [nsmutablestringstring]; -  the[MSTR setString:@"I didn't change ."]; -  -      -  +Self.retainstr =MSTR; -  +Self.copystr =MSTR; A  atSelf.retainmstr =MSTR; -  -Self.copymstr =MSTR; -  -      -  inNSLog (@"retainstr:%@", self.retainstr); -  toNSLog (@"copystr:%@", self.copystr); +  -NSLog (@"retainmstr:%@", self.retainmstr); the  *NSLog (@"copymstr:%@", self.copymstr); $ Panax NotoginsengNSLog (@"\ n"); -  the      +  A[MSTR setString:@"I've changed."]; the  +      -  $NSLog (@"retainstr:%@", self.retainstr); $  -NSLog (@"copystr:%@", self.copystr); -  theNSLog (@"retainmstr:%@", self.retainmstr); - WuyiNSLog (@"copymstr:%@", self.copymstr); the  -NSLog (@"\ n"); Wu  -   About  $NSString *str =@"I'm coming.";//[[NSString alloc] initwithformat:@ "I came"];//two ways are the same.  -  -Self.retainstr =str; -  ASelf.copystr =str; +  theSelf.retainmstr =[str mutablecopy]; -  $Self.copymstr =[str mutablecopy]; the  the   the  theNSLog (@"retainstr:%@", self.retainstr); -  inNSLog (@"copystr:%@", self.copystr); the  theNSLog (@"retainmstr:%@", self.retainmstr); About  theNSLog (@"copymstr:%@", self.copymstr); the  theNSLog (@"\ n"); +  -      the Bayistr =@"I'm leaving.";//[[Nsstringalloc] initwithformat:@ "I'm Gone"];//two ways are the same the  the   -  -NSLog (@"retainstr:%@", self.retainstr); the  theNSLog (@"copystr:%@", self.copystr); the  theNSLog (@"retainmstr:%@", self.retainmstr); -  theNSLog (@"copymstr:%@", self.copymstr); the  theNSLog (@"\ n");94  the   the  the The printing results are as follows:98  About  --Ten- A  -: -:14.858stringdemo[1515:11303] Retainstr: I haven't changed . - 101  --Ten- A  -: -:14.860stringdemo[1515:11303] Copystr: I haven't changed .102 103  --Ten- A  -: -:14.861stringdemo[1515:11303] Retainmstr: I haven't changed .104  the  --Ten- A  -: -:14.862stringdemo[1515:11303] Copymstr: I haven't changed .106 107  --Ten- A  -: -:14.863stringdemo[1515:11303] 108 109  --Ten- A  -: -:14.864stringdemo[1515:11303] Retainstr: I've changed. the 111  --Ten- A  -: -:14.865stringdemo[1515:11303] Copystr: I haven't changed . the 113  --Ten- A  -: -:14.866stringdemo[1515:11303] Retainmstr: I've changed. the  the  --Ten- A  -: -:14.867stringdemo[1515:11303] Copymstr: I haven't changed . the 117  --Ten- A  -: -:14.868stringdemo[1515:11303] 118 119  --Ten- A  -: -:14.869stringdemo[1515:11303] Retainstr: I'm coming. - 121  --Ten- A  -: -:14.869stringdemo[1515:11303] Copystr: I'm coming.122 123  --Ten- A  -: -:14.870stringdemo[1515:11303] Retainmstr: I'm coming.124  the  --Ten- A  -: -:14.871stringdemo[1515:11303] Copymstr: I'm coming.126 127  --Ten- A  -: -:14.872stringdemo[1515:11303]  - 129  --Ten- A  -: -:14.873stringdemo[1515:11303] Retainstr: I'm coming. the 131  --Ten- A  -: -:14.874stringdemo[1515:11303] Copystr: I'm coming. the 133  --Ten- A  -: -:14.875stringdemo[1515:11303] Retainmstr: I'm coming.134 135  --Ten- A  -: -:14.876stringdemo[1515:11303] Copymstr: I'm coming.

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.