Weak and strong property setter attributes in Objective-C

前端 未结 5 2016
北海茫月
北海茫月 2020-11-29 15:31

What is the difference between weak and strong property setter attributes in Objective-C?

@property(retain, [weak/strong]) __attribute__((NSObject)) CFDictio         


        
5条回答
  •  鱼传尺愫
    2020-11-29 16:38

    To call out the parts of the docs referenced by Robert that answer your last two questions explicitly:

    // The following declaration is similar to "@property(assign) MyClass *myObject;"
    // except that if the MyClass instance is deallocated,
    // the property value is set to nil instead of remaining as a dangling pointer.
    @property(weak) MyClass *myObject;
    

    This is referred to as a zeroing weak reference. You can create weak references that are not zeroing weak references using __unsafe_unretained, but as the name implies, this is generally not recommended.

    Also in the docs:

    Weak references are not supported in Mac OS X v10.6 and iOS 4.
    

提交回复
热议问题