【问题标题】:Is typing strong in properties really necessary? [duplicate]在属性中输入 strong 真的有必要吗? [复制]
【发布时间】:2014-02-16 09:40:08
【问题描述】:
@property (nonatomic, strong) NSString *dude;
@property (nonatomic) NSString *dude;
@property (nonatomic, weak) NSString *dude;

这三个到底有什么区别?

【问题讨论】:

    标签: ios objective-c properties


    【解决方案1】:

    第一个和第二个没有区别,因为“strong”是default & implicit attribute

    第三个使用弱引用,这意味着当对象被最后一个所有者释放时,dude属性变为nil。

    哦,最后,NSString 属性实际上应该用“NSString *”声明。

    【讨论】:

    • 通常对于字符串,您应该考虑使用copy
    猜你喜欢
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 2011-09-08
    • 2018-04-05
    • 2021-01-25
    • 1970-01-01
    • 2015-12-31
    • 2014-06-02
    相关资源
    最近更新 更多