自我限制永远不会超越后卫语句

问题描述 投票:0回答:0
[weak self]

。我遇到的问题是,代码从未执行过我的语句:

guard
当设置我的
func zoomInButton() -> CPMapButton {
    
    let zoomInButton = CPMapButton { [weak self] button in
        
        // Code never continues past here.
        guard let self = self else { return }
        
        if let mapView = self.mapViewController?.mapView {
            
            mapView.setZoomLevel(mapView.zoomLevel + 1, animated: true)
            
        }
        
    }
    
    let bundle = Bundle.main
    zoomInButton.image = UIImage(named: "carplay_plus", in: bundle, compatibleWith: self.traitCollection)
    return zoomInButton
    
}

CPMapTemplate
没有人会看到为什么它不会继续过去的原因?我已经查看了其他代码示例,这看起来正确。
    

我弄清楚了。我打电话给我的班级,但从未有过强有力的提及,因此上面的代码不起作用。我创建了一个共享对象,并解决了问题。
    


swift closures carplay
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.