Chirag Dj Chirag Dj - 4 months ago 97
Swift Question

How to make an array of UILabel in Swift

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.
}

}

Answer
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
}