I have a situation where I have a leak that I do not understand. I would be very grateful if someone could explain it to me and offer an idea of how I can make the pattern work without leaking:
Consider two code snippets, the first of which leaks, while the second does not. Case 1: This example leaks 2 32-byte objects.. in FontSelectorDialog.swift: override func prepare(for segue: UIStoryboardSegue, sender: Any?) { switch segue.identifier! { < ... > case "ChooseTextColor" : let target = segue.destination as! ColorChooser target.textChooserType = .text // <=== < ... > } case "ChooseBackgroundColor" : let target = segue.destination as! ColorChooser target.textChooserType = .bkgnd // <=== < ... > } default : break } in ColorChooser.swift: internal enum ColorCat { // <=== case: .text // <=== case: .bkgnd // <=== } // <=== internal class ColorChooser : UITableViewController { internal var textChooserType : ColorCat = .text // <=== < ... > } Case 2: This example does not leak... in FontSelectorDialog.swift: override func prepare(for segue: UIStoryboardSegue, sender: Any?) { switch segue.identifier! { < ...> case "ChooseTextColor" : let target = segue.destination as! ColorChooser target.textChooserType = true // <=== < ... > } case "ChooseBackgroundColor" : let target = segue.destination as! ColorChooser target.textChooserType = false // <=== < ... > } default : break } in ColorChooser.swift: internal class ColorChooser : UITableViewController { internal var textChooserType : Bool = true // <=== < ... > } Can someone explain why? And how can I implement this using an enum. I want to use an enum here because: (a) it is easier to read and understand and seems more “swiftly” (b) Someday, I may want to add additional options, which would be easy with an enum but difficult using the current (Bool) implementation. Cheers, Rick Aurbach
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users