簡體   English   中英

什么是強屬性屬性

[英]What is the strong property attribute

我正在為開發人員使用 Xcode 測試版,並注意到一些細微的差異。 其中包括聲明屬性的新屬性。

@property(strong)IBOutlet NSArrayController *arrayControl;

我的問題是:強屬性是什么意思? 它會取代一些舊的,還是全新的? 我搜索了谷歌和開發人員文檔,但沒有找到任何東西。 在我知道它是什么之前,我會猶豫使用它。

提前致謝

它是retain屬性的替代品,作為Objective-C 自動引用計數 (ARC)的一部分。 在非 ARC 代碼中,它只是retain的同義詞。

強引用是對阻止它被釋放的 object 的引用。 換句話說,它創建了所有者關系。 而以前你會這樣做:

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

在 ARC 下,我們執行以下操作以確保 class 實例獲得引用的 object 的所有權權益(即,在擁有者之前無法解除分配)。

**// ARC Compliant Declaration
@property(strong) NSObject *obj;**

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 object 的屬性為“強”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM