对于i in 0,会导致三个确切的错误

时间:2017-01-09 20:50:59

标签: swift

我有一个walkthroughdidscoll函数,然后是一个动画函数,可以帮助执行缩放,旋转和动画。这是代码。这是我得到的错误的图像。

Error Image

func walkthroughDidScroll(_ position: CGFloat, offset: CGFloat) {



    for(i in 0 ..< subsWeights.count ){

        // Perform Transition/Scale/Rotate animations
        switch animation{

        case .Linear:
            animationLinear(i, offset)

        case .Zoom:
            animationZoom(i, offset)

        case .Curve:
            animationCurve(i, offset)

        case .InOut:
            animationInOut(i, offset)
        }

        // Animate alpha
        if(animateAlpha){
            animationAlpha(i, offset)
        }
    }
}

2 个答案:

答案 0 :(得分:1)

删除括号。

for i in 0 ..< subsWeights.count {

答案 1 :(得分:0)

你应该这样做:

func walkthroughDidScroll(_ position: CGFloat, offset: CGFloat) {



    for i in 0 ..< subsWeights.count {

        // Perform Transition/Scale/Rotate animations
        switch animation{

        case .Linear:
            animationLinear(i, offset)

        case .Zoom:
            animationZoom(i, offset)

        case .Curve:
            animationCurve(i, offset)

        case .InOut:
            animationInOut(i, offset)
        }

        // Animate alpha
        if(animateAlpha){
            animationAlpha(i, offset)
        }
    }
}

这是这种类型的for循环的基本结构,带有一个例子:

    for index in 1...5 {
        print("\(index) times 5 is \(index * 5)")
    }

// 1 times 5 is 5
// 2 times 5 is 10
// 3 times 5 is 15
// 4 times 5 is 20
// 5 times 5 is 25