Question: iam unable to set backgroundcolor for label at runtime

```
func example() {
  let lbl: UILabel = UILabel()
  let arrTemp: NSMutableArray = NSMutableArray()
  arrTemp.addObject(lbl)
  let tempButton: UIButton? = arrTemp.objectAtIndex(0) as? UIButton
  tempButton.backgroundColor = UIColor.whiteColor()
}

```

Answer: 
Your logic is wrong for several reasons.
Let's see what you are doing

1. You are adding a `UILabel` to `arrTemp`.

```
arrTemp.addObject(lbl)

```

Now `arrTemp` does contain `UILabel` as only element

2. Next you retrieve the first element of arrTemp and try to cast it as `UIButton`.

```
let tempButton: UIButton? = arrTemp.objectAtIndex(0) as? UIButton

```

Of course the conditional cast will always fail (given the current code) and tempButton will be populated with `nil`.

3. You are accessing a property of tempButton (which is an Optional Value) without unwrapping it. The Swift compiled does not allow you to do this.

```
tempButton.backgroundColor = UIColor.whiteColor()

```
4. You could update the last line to make the compiler happy

```
tempButton?.backgroundColor = UIColor.whiteColor()

```

but the last assignment will never be executed since `tempButton` will always be `nil`.

Now a question: what are you trying to do? What do you want to achieve putting a `UILabel` into an array and then trying to use that label as a `UIButton`?
A `UILabel` is a subclass of `UIView`; a `UIView` has a settable property of `backgroundColor`. So, to set a `UILabel` color use simply:

```
func example() {
  let lbl: UILabel = UILabel()
  lbl.backgroundColor = UIColor.whiteColor()
  // do something with lbl.
}

```