[英]Swift iOS -Should Deinit get called inside child View Controller when added as a child to another View Controller?
[英]Why don't the deinit get called when i go to another view?
我的導航控制器中有一個供我的視圖控制器使用的對象,當我返回時,它不會被初始化,我想知道為什么。
這是班
class MyLeague {
var league : League?
var fixtures : [Fixture] = []
var teams : [Team] = []
var standings : [Standing] = []
init() {
print("Creating")
}
deinit {
print("Deallocating")
}
}
這是我在ViewController中創建它的方式
let selectedLeague = MyLeague()
這樣我設置屬性
APIManager.shared.request(url: url, onSuccess: { [weak self] (data) in
do {
let fixtureData = try JSONDecoder().decode(FixturesResponse.self, from: data)
self?.selectedLeague.fixtures = fixtureData.api.fixtures
self?.competitionTableView.reloadData()
} catch {
print(error)
}
}) { (error) in
print(error)
}
嘗試使用樂器在代碼中查找任何保留周期。
您可以從“產品”->“配置文件”中訪問它,然后選擇“分配”工具並使用它來跟蹤在導航時哪個對象正在調用您的班級。 希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.