我有用objective-c撰寫的CBPeripheral擴展,變數bleManagerStore參考BleManagerStore實體。當 CBPeripheral 實體自動釋放時,對 bleManagerStore 的參考計數也會自動減少嗎?如果沒有,我該如何解決?
我對變數 currentSeq 也有同樣的問題。
謝謝。
目標c代碼
@implementation CBPeripheral(com_megster_ble_extension)
BleManagerStore *bleManagerStore;
NSNumber *currentSeq;
-(void)setBleManagerStore:(BleManagerStore*) store {
bleManagerStore = store;
}
-(BleManagerStore*)getBleManagerStore {
return bleManagerStore;
}
-(void) setSeq:(NSNumber*) seq {
currentSeq = seq;
}
@end
SWIFT代碼
class BleManager {
var peripheral: CBPeripheral?
func test() {
peripheral?.setBleManagerStore(BleManagerStore())
peripheral?.setSeq(NSNumber(value: 12))
}
}
uj5u.com熱心網友回復:
不會。Swift 使用Automatic Reference Counting自動處理記憶體。這會自動從不再需要它的類實體中釋放記憶體。
但是,參考計數僅適用于類的實體,如 swift 語言指南中所述
參考計數僅適用于類的實體。結構和列舉是值型別,而不是參考型別,并且不是通過參考存盤和傳遞的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/521839.html
標籤:迅速目标-c
上一篇:在加載iOS視圖之前,應如何在locationManagerDidChangeAuthorization中檢查CLLocationManager狀態?
