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

后端 未结 1 1667
悲&欢浪女
悲&欢浪女 2021-01-22 11:35

In my view controller:

class FoodAddViewController: UIViewController, UIPickerViewDataSource, UITextFieldDelegate, UIPickerViewDelegate {

    let TAG = \"FoodAd         


        
相关标签:
1条回答
  • 2021-01-22 11:48

    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
    }
    
    0 讨论(0)
提交回复
热议问题