Learn Courses My Dashboard

Lesson 4 Challenge (14 day challenge)

I have attempted the challenge on lesson 4 of the 14 day coding challenge (with London and Toronto graphics). The two images are showing on what appear to be different preview screens, despite the fact I have included the VStack at the start; can anyone point me as to what I may be doing wrong? cheers x

Hi @jackmohan

Can you post your code in a reply.

Place 3 back-ticks ``` on the line above and 3 back-ticks on the line below your code to format it nicely like this:

Hi Chris, sorry I just saw this. Here is my code from the lesson 4 challenge (I fixed the page but now I can’t see the images). Any help appreciated, cheers!

import SwiftUI

struct ContentView: View {
    var body: some View {
        
        VStack{
            
            ZStack{
             Image("toronto")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .cornerRadius(10)
                
                VStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) {
                    Text("CN Tower")
                        .font(.largeTitle)
                        .padding([.top, .leading, .trailing])
                    
                    Text("Toronto")
                        .font(.caption)
                        .padding([.leading, .bottom, .trailing])
                }
                .background(Color.black)
                .opacity(/*@START_MENU_TOKEN@*/0.8/*@END_MENU_TOKEN@*/)
                .cornerRadius(10)
               
                .foregroundColor(Color.white)
                
            }.padding()
            
            ZStack {
                Image("london")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .cornerRadius(10)
                
                VStack(alignment:.center) {
                    Text("Big Ben")
                        .font(.largeTitle)
                        .padding([.top, .leading, .trailing])
                    Text("London")
                        .font(.caption)
                        .padding([.leading, .bottom, .trailing])
                    
                }
                .background(Color.black)
                .opacity(/*@START_MENU_TOKEN@*/0.8/*@END_MENU_TOKEN@*/)
                .cornerRadius(10)
                
                .foregroundColor(.white)
            }.padding()
                }
            }
        }

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

@jackmohan

Your code works fine in the version I have. Maybe clean your project and try again. Use the keyboard short cut Shift + Command + K to clean your project then Run it in the simulator.

If that does not work then make sure that the images are in the Assets catalogue and that the “Target Membership” is selected for each image. To check that, Open the assets catalogue, select the images in turn and then look at the Identity Inspector over on the right and ensure that the check mark is on for Target Membership as shown in the attached image.