deinit

Swift - Is the correct place to call .removeObserver always deinit()?

北战南征 提交于 2021-02-08 08:01:33
问题 New StackOverflow user here (first time posting, long time lurking w/o an account). Before I begin, these are some previously answered questions that I've found to be helpful but have not completely resolved my issue: How to safely removeObserver (Swift) The right place to call .removeObserver for NSNotificationCenter = Swift deinit()? From these I have constructed a BaseView controller with which to control the behaviour of my app under various circumstances (e.g. an API call to check for

Swift - Is the correct place to call .removeObserver always deinit()?

独自空忆成欢 提交于 2021-02-08 08:01:25
问题 New StackOverflow user here (first time posting, long time lurking w/o an account). Before I begin, these are some previously answered questions that I've found to be helpful but have not completely resolved my issue: How to safely removeObserver (Swift) The right place to call .removeObserver for NSNotificationCenter = Swift deinit()? From these I have constructed a BaseView controller with which to control the behaviour of my app under various circumstances (e.g. an API call to check for

Why is deinit not called until UIView is added to parent again?

旧街凉风 提交于 2020-03-20 06:25:50
问题 I have a UIView that am adding to a UIViewController and am generally testing de-initialization to make sure I am doing things right. But when I don't set the variable in my viewController to nil and only use .removeFromSuperView() , the deinit() method in UIView won't be called until I add the UIView another time then its called. But if I use removeFromSuperView() and set the variable to nil then deinit() is called right away. Why is that? Here's UIView() class: class TestView: UIView {

Why is deinit not called until UIView is added to parent again?

混江龙づ霸主 提交于 2020-03-20 06:25:38
问题 I have a UIView that am adding to a UIViewController and am generally testing de-initialization to make sure I am doing things right. But when I don't set the variable in my viewController to nil and only use .removeFromSuperView() , the deinit() method in UIView won't be called until I add the UIView another time then its called. But if I use removeFromSuperView() and set the variable to nil then deinit() is called right away. Why is that? Here's UIView() class: class TestView: UIView {

Why is deinit not called until UIView is added to parent again?

有些话、适合烂在心里 提交于 2020-03-20 06:25:34
问题 I have a UIView that am adding to a UIViewController and am generally testing de-initialization to make sure I am doing things right. But when I don't set the variable in my viewController to nil and only use .removeFromSuperView() , the deinit() method in UIView won't be called until I add the UIView another time then its called. But if I use removeFromSuperView() and set the variable to nil then deinit() is called right away. Why is that? Here's UIView() class: class TestView: UIView {

Lazy initialization and deinit

五迷三道 提交于 2019-12-24 06:49:56
问题 I would to know if it's possible, in my view controller, use a lazy property and in deinit method call a method of my lazy property only if it was initialized. Below some code: fileprivate lazy var session: MySession = { let session: MySession = MySession() session.delegate = self return session }() deinit { session.delete() } In this way, when session.delete() in the deinit method is called and session hasn't been used (so is still nil ), it's initialized and then delete is called. I don't

UISplitViewController: Deinit DetailView in collapsed mode

青春壹個敷衍的年華 提交于 2019-12-22 05:58:49
问题 I've been struggling on this for a while now, but I wasn't able to find a solution: I've got an iOS 9 app that supports all device families, uses size classes and is programmed with Swift 2.0. I'm using a UISplitViewController and everything works as I want, except in a collapsed environment (e.g. on an iPhone). The Master-ViewController is a UITableViewController that triggers a replace segue when a cell is selected. In a collapsed environment this means, that the detailViewcontroller gets

Is cleaning up strong references in deinit a correct pattern?

可紊 提交于 2019-12-13 12:22:57
问题 There are several resources (blog, SO question, plus I've seen it used everywhere) that recommend removing an observer from the NotificationCenter in the deinit of the UIViewController , e.g.: deinit { NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil) NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil) } Now while according to another blog entry I don't have to care about removing

Does Cocoa connection binding to NSToolbarItem prevent deinitializing?

好久不见. 提交于 2019-12-11 01:13:00
问题 Trying to set the selected segment of an NSToolbarItem that's an NSSegmentedControl via connection binding to a property (optionSegment). Subclassing the window controller as such class MyWindow: NSWindowController { dynamic var optionSegment: Int = 0 override func windowDidLoad() { super.windowDidLoad() } } Alternately, put the optionSegment property in the NSDocument subclass and bind to that. Each work. The problem is that with this binding, or seemingly any binding to NSToolbarItem , none

how to make deinit take effect in swift

微笑、不失礼 提交于 2019-12-07 19:57:37
问题 I have a Car class. Let's say a car goes to the junkyard, this car should no longer be counted in the total population. I have the deinit function, but how do I systematically remove a car from the car population? In other words, how do I get the deinit to take effect? I have a class variable isJunk but don't know how to use it to make this work. class Car { static var population: Int = 0 var isJunk: Bool = false var color: String var capacity: Int var driver: Bool? var carOn: Bool = false