You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current implementation of YoshiSingleSelectionMenu doesn't allow to use weak self in didSelect handler because upon calling super.init in subclass initializer self will be passed before finishing initialization and app will crash with EXC_BAD_ACCESS exception.
Demo
import UIKit
import Yoshi
/// Oversimplified class I have on a project to stub API requests with OHHTTPStubs library
classAPIDebugMenu:YoshiSingleSelectionMenu{varactiveStub:String?{
didSet {print("Set to \(String(describing: activeStub))")}}init(){letoptions=[YoshiSingleSelection(title:"Off", subtitle:nil),YoshiSingleSelection(title:"HTTP 404", subtitle:nil),YoshiSingleSelection(title:"HTTP 503", subtitle:nil),]
super.init(title:"API", options: options, selectedIndex:0){[weak self](item)inself?.activeStub = item.title
}}}classYoshiExcBadAccess:UIViewController{overridefunc viewDidLoad(){
super.viewDidLoad()letitem=APIDebugMenu()Yoshi.setupDebugMenu([item])}}
It's possible to refactor our implementation so the activeStub will be managed by an object retained in a closure to fix this issue. But what the purpose of having open class YoshiSingleSelectionMenu?
Possible solution
Make didSelect public so it can be written after initialization.
The text was updated successfully, but these errors were encountered:
Current implementation of
YoshiSingleSelectionMenu
doesn't allow to useweak self
indidSelect
handler because upon callingsuper.init
in subclass initializerself
will be passed before finishing initialization and app will crash with EXC_BAD_ACCESS exception.Demo
It's possible to refactor our implementation so the
activeStub
will be managed by an object retained in a closure to fix this issue. But what the purpose of havingopen class YoshiSingleSelectionMenu
?Possible solution
Make
didSelect
public so it can be written after initialization.The text was updated successfully, but these errors were encountered: