What is the strong property attribute

前端 未结 3 2145
终归单人心
终归单人心 2020-12-12 20:27

I am using the Xcode beta for developers, and am noticing some subtle differences. Among them is a new attribute for declared properties.

@property(strong)IB         


        
相关标签:
3条回答
  • 2020-12-12 20:44

    As we know, we cannot release any object in an ARC-based project in iOS 5. So when we want to retain any object for further use at a later stage and don't want ARC to remove the object from memory, then we set the property for the object as "Strong".

    0 讨论(0)
  • 2020-12-12 20:45

    It's a replacement for the retain attribute, as part of Objective-C Automated Reference Counting (ARC). In non-ARC code it's just a synonym for retain.

    0 讨论(0)
  • 2020-12-12 20:46

    A strong reference is a reference to an object that stops it from being deallocated. In other words it creates a owner relationship. Whereas previously you would do this:

    **// Non-ARC Compliant Declaration
    @property(retain) NSObject *obj;**
    

    Under ARC we do the following to ensure a class instance takes an ownership interest a referenced object (i.e. so it cannot be deallocated until the owner is).

    **// ARC Compliant Declaration
    @property(strong) NSObject *obj;**
    
    0 讨论(0)
提交回复
热议问题