Xcode Playground crash 100%

Hi all,
I have swift code on play ground which can make Xcode 10.1 crash 100% (also crash on 10.2 beta). Code:

import UIKit

class ParentVC: UIViewController {
    lazy var button: UIButton = {
        let b = UIButton(frame: CGRect.zero)
        b.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
        return b
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.addSubview(button)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        print("ParentVC-viewWillAppear")
    }
    
    @objc func buttonAction() {
        print("ParentVC-->buttonActionTap")
        checkOTP()
    }
    
    func checkOTP() {
        if randomNumber() % 2 == 0{
//            trackEventAnalytic(111111)
            trackEventNumber()
        } else {
//            trackEventAnalytic(33333)
            trackOddNumber()
        }
    }
    
    func trackOddNumber(){
        trackEventAnalytic(33333)
    }
    
    func trackEventNumber() {
        trackEventAnalytic(111111)
    }
    
    func randomNumber() -> Int {
       return Int.random(in: 0 ... 10)
    }
    
    func trackEventAnalytic(_ eventId: Int) {
        print("---->ParentVC-trackEventAnalytic:\(eventId)")
    }
    
}

class ChildVC: ParentVC {
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        print("ChildVC-viewWillAppear")
    }
    
    override func trackEventAnalytic(_ eventId: Int) {
        //print result: ChildVC:trackEventAnalytic---->111111
        //How to pass eventId with value 2222 instate of 111111
        print("ChildVC:trackEventAnalytic---->\(eventId)")
//        super.trackEventAnalytic(eventId)
    }
    
    override func trackOddNumber() {
        trackEventAnalytic(2222222222222)
    }
    
    override func trackEventNumber() {
        trackEventAnalytic(22)
    }
}

//let c = ChildVC()
//c.button.sendActions(for: .touchUpInside)

let p = ParentVC()
p.button.sendActions(for: .touchUpInside)

let view = UIViewController()
view.view.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
view.view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
p.present(view, animated: true, completion: nil)

The action which make Xcode crash:

1 Like

That reproduces for me with the released version of Xcode 10.2.

Xcode shouldn’t crash regardless of what your playground is doing, so this is clearly bugworthy. Please file a bug, then post your bug number here, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

1 Like

For now, a workaround is to change the button to not have zero width or height. Thank you for sharing the reproducing case.

    lazy var button: UIButton = {
        let b = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20)) // zero here caused the issue
        b.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
        return b
    }()
1 Like
Terms of Service

Privacy Policy

Cookie Policy