Learn Courses My Dashboard

Error: Cannot assign to immutable expression of type '[String].Type'

Hi there,

I’m trying to use int values 0-10 in my UIPickerView but there’s some errors I don’t really understand.

Here’s my code - I’m putting the UIPickerView inside a TextField I just thought it looked neater that way

class AddViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
    @IBOutlet weak var repeatTextField: UITextField!
    @IBOutlet weak var startPicker: UIDatePicker!
    @IBOutlet weak var endPicker: UIDatePicker!
    @IBOutlet weak var doneButton: UIBarButtonItem!
    var pickerView = UIPickerView()
    var numbers = [String] = []
    //used to hand back the information added by the user e.g., date and frequency.
    //public var completion: ((String, TimeZone, TimeZone) -> Void)?
    override func viewDidLoad() {
        pickerView.delegate = self
        pickerView.dataSource = self
        repeatTextField.inputView = pickerView
        let formatter = DateFormatter()
        formatter.dateFormat = "HH:mm"
        pickerView.delegate = self
        pickerView.dataSource = self
        for i in 1..<10 {
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return 10
    internal func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return String(row + 1)

This is where the error shows up:

var numbers = [String] = []

This is what I’m trying to attain:

Could you please help me how to resolve this? Thanks in advance! :))

Okay that was such a silly typo.

Solution is:

var numbers : [String] = []