Default parameter values error: “instance member cannot be used on type viewcontroller”

≯℡__Kan透↙ 提交于 2019-12-02 02:34:11

You cannot use instance variables in function declarations. Call the function with your textFields array and pass the parameters.

func validateAllTextFields(textFields: [UITextField] ) -> Bool {

    var result = true
    for textField in textFields {
        result = validateTextField(textField) && result
    }
    return result
}

somehwere in your class:

validateAllTextFields(textFields: [foodName, foodPortion, foodCalories])

Or you check inside of your function if textFields is empty and than u use the instance variables

func validateAllTextFields(textFields: [UITextField] ) -> Bool {
    if textFields.count == 0 {
        textFields = [foodName, foodPortion, foodCalories]
    }
    var result = true
    for textField in textFields {
        result = validateTextField(textField) && result
    }
    return result
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!