Reputation: 615
// ViewController.swift
// FunFacts
//
// Created by Moises Miguel Hernandez on 11/27/17.
// Copyright © 2017 Moises Miguel Hernandez. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet var funFactLabel: [UILabel]!
override func viewDidLoad() {
super.viewDidLoad()
funFactLabel.text = "An Interesting Fact"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}//end of recive memory warning
}//end of viewController
I am using Xcode and Swift 4. I am just starting out and taking a course from team treehouse.
In the video tutorial they easily did the funFactLabel.text = "Some Fun fact"
When I try to do that it gives me this error:
Value of type '[UILabel]' has no member 'text'
I don't think I am doing anything wrong. I just want to change the text of the label to say: "Some Fun Fact".
Upvotes: 1
Views: 5905
Reputation: 3657
It seems like you have made an OutletCollection
If you made an OutletCollection
it will always an array try to choose only Outlet
.
See here:
OutletCollection
@IBOutlet var funFactLabel: [UILabel]!
Outlet
@IBOutlet var funFactLabel: UILabel!
Upvotes: 0
Reputation: 4891
Your funFactLabel is an array of UILabel.
Either do this :
@IBOutlet var funFactLabel: UILabel!
Or this but for this you have to take an array and you have to append your labes in it. You can't make an IBOutlet as an array:
override func viewDidLoad() {
super.viewDidLoad()
for label in funFactLabel{
label.text = "An Interesting Fact"
}
}
But I why an array of label as IBOutlet ? Never saw someone doing that. For each label take one IBOutlet.
Right click on label and Drag Referencing Outlets always, 2nd one. Ignore Course Detail, that's just text for my UILabel.
Upvotes: 1
Reputation: 2315
You declared funFactLabel
as an array of labels.
replace the line
@IBOutlet var funFactLabel: [UILabel]!
by
@IBOutlet var funFactLabel: UILabel!
Upvotes: 2
Reputation: 1278
Your problem is that [UILabel]
is an array of UILabels.
Everything in braces []
is an array. So you could have an array of strings: [String]
Just change the type to a plain UILabel
like so:
@IBOutlet var funFactLabel: UILabel!
Upvotes: 3