3

How do I make an array of UILabel in Swift. When I try to, I get an error like ViewController.Type'dose not have a member named 'Lable00' my code:

import UIKit

class ViewController: UIViewController {

    let individualScores = [75, 43, 103, 87, 12]

    @IBOutlet var Lable00: UILabel?
    @IBOutlet var Lable01: UILabel?
    @IBOutlet var Lable02: UILabel?
    @IBOutlet var Lable03: UILabel?
    @IBOutlet var Lable04: UILabel?

    var Lable_Arr = [Lable00, Lable01, Lable02, Lable03, Lable04]

    override func viewDidLoad() {
        super.viewDidLoad()

        for score in individualScores {
        }
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

3 Answers 3

5
private var labels:[UILabel]()

override func viewDidLoad() 
{
    super.viewDidLoad()
    labels.append(Lable00)
    labels.append(Lable01)
    labels.append(Lable02)
    labels.append(Lable03)
    labels.append(Lable04)

    // do stuff with the labels view
}
Sign up to request clarification or add additional context in comments.

Comments

3

for Swift 2 :

var labels:[UILabel]=[]

Comments

2

In ViewDid load you don't have to append, you can just assign a new array to labels like so:

var labels:[UILabel]()

override func viewDidLoad() {
  super.viewDidLoad()

  labels = [label01, label02, label03, label04]

  // do stuff with the labels view
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.