UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

100 Days of Swift and UIKit Project 2 Flag not changing.

Forums > SwiftUI

Hey everyone so I am following along the tutorial for project 2. I have redone it 3 times and it still does not work. When I run my app it only displays the US image 3 times despite at this point copying and pasting his code. I hav done exactly what he says for IB builder. Also I am not even able to click the button, I know if I click the button nothing will happen because I did not add code for it, however, the button should still "click" and do nothing. It is not even clicking.

import UIKit

class ViewController: UIViewController {
    @IBOutlet var button1: UIButton!

    @IBOutlet var button2: UIButton!

    @IBOutlet var button3: UIButton!

    var countries = [String]()
    var score = 0
    override func viewDidLoad() {
        super.viewDidLoad()

        countries += ["estonia", "france", "germany", "ireland", "italy", "monaco", "nigeria", "poland", "russia", "spain", "uk", "us"]

        askQuestion()

    }

    func askQuestion() {
        button1.setImage(UIImage(named: countries[0]), for: .normal)
        button2.setImage(UIImage(named: countries[1]), for: .normal)
        button3.setImage(UIImage(named: countries[2]), for: .normal)
    }

}

So I solved my issue by the countries array string, I had to match the file names in the asset pictures with the names of the flag names in countries. I am confused why his code worked for him when he kept all the countires names as lower case?

3      

HackingWithSwift.com has a specific forum for 100 Days of Swift. You've posted your question in the SwiftUI forum.

I recommend deleting your question here and reposting it to the 100 Days of Swift forum.

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.