swift如何发送&nil到func?

时间:2017-09-18 10:05:03

标签: swift null

func setupCircular(circularLayer:inout CAShapeLayer?){
    if (circularLayer == nil) {
        circularLayer = CAShapeLayer()
    }else{

    }
}
setupCircular(circularLayer: &nil)

怎么写?

1 个答案:

答案 0 :(得分:2)

您不能在Swift中将值用作inout参数。您需要创建一个CAShapeLayer类型的变量,将其赋值nil并将其用作函数的输入参数。

func setupCircular(circularLayer:inout CAShapeLayer?){
    if (circularLayer == nil) {
        circularLayer = CAShapeLayer()
    }else{

    }
}

var circ: CAShapeLayer? = nil
setupCircular(circularLayer: &circ)