iOS Build a Simple iPhone App with Swift View Controllers and Views Creating IBOutlets

meitav asulin
meitav asulin
1,123 Points

Why the fundable.text was written in the override init and not before?

why?

2 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points

It is difficult to answer questions when you do not post the code. If you could please post the code I would be happy to assist you!

meitav asulin
meitav asulin
1,123 Points

import UIKit

class ViewController: UIViewController {

@IBOutlet weak 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.
}

@IBAction func showFact() {
    funFactLabel.text = "Another interesting fact"
}

} Why did he write this in the override init and not outside the init- funFactLabel.text = "An interesting fact!"

Jeff McDivitt
Jeff McDivitt
23,970 Points

Because then it will appear when the app is loaded; that is why it is inside viewDidLoad