IOS @proporty 关键字(一)retain strong
@interface user : nsobject  
  
@property (nonatomic,retain) nsstring* tretain;  
@property (nonatomic,assign) nsstring* tassign;  
@property (nonatomic,copy) nsstring* tcopy;  
  
@end  

类user有个属性tretain, 只是测试就用nsstring类型了(此类型一般用copy, 因为可能是个nsmutablestring,不希望在赋值后被其他地方修改内容)。

user* user = [[user alloc]init];  
  
nsstring* testretain = [nsstring stringwithformat:@"retain"];  
nslog(@"testretain.retaincount=%lu",(unsigned long)testretain.retaincount);  //1  
  
user.tretain = testretain;  
nslog(@"testretain.retaincount=%lu",(unsigned long)testretain.retaincount);   //2  
nslog(@"user.tretain.retaincount=%lu",(unsigned long)user.tretain.retaincount); //2  
  
nsstring* testretain2 = @"retain2";  
nslog(@"testretain2.retaincount=%lu",(unsigned long)testretain2.retaincount); //4294967295 自动释放对象  返回max unsigned long  
  
  
user.tretain = testretain2;  
nslog(@"testretain.retaincount=%lu",(unsigned long)testretain.retaincount);   //1  
nslog(@"testretain2.retaincount=%lu",(unsigned long)testretain2.retaincount); //4294967295  
nslog(@"user.retainvalue.retaincount=%lu",(unsigned long)user.tretain.retaincount); //4294967295  
  
  
nsstring* testretain3 = [nsstring stringwithformat: @"retain3"];  
nslog(@"testretain3.retaincount=%lu",(unsigned long)testretain3.retaincount); //1  
  
[testretain3 retain];  
nslog(@"testretain3.retaincount=%lu",(unsigned long)testretain3.retaincount); //2  
  
nsstring* testretain4 = [nsstring stringwithstring:testretain3];  
nslog(@"testretain3.retaincount=%lu",(unsigned long)testretain3.retaincount); //3  
nslog(@"testretain4.retaincount=%lu",(unsigned long)testretain4.retaincount); //3  

strong是arc后引入的关键字, 在arc环境中等同于retain。

 

nssring* str = [nsstring stringwithstring:字符串];   此方法相当于上文对一个retain属性赋值。   若后面的字符串参数的计数为4294967295,则str的计数也是。   若字符串参数可计数, 例如1, 则执行后计数加1.

本文链接:https://2i3i.com/7128494.html ,转载请注明来源地址。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇