Learn Courses My Dashboard

Thank you note for help

Thank you for all the help! Since I haven’t figured out how to do these last three things for my app. I will get help from someone else, unless someone can give me more detailed help

I’m not sure what kind of help you need, but if you can share more details on the topic you’re interested in maybe we can share our insights. :slight_smile:

Maybe you can share what are the 3 things you have struggling with.

Thank you! I’ll do one at a time to make it less confusing.
First thing, how do I fix this error, I’ve tried a couple of things but nothing worked.
Screen Shot 2022-02-16 at 8.36.59 PM

Can you move the code from line 45 up to line 49 to the bottom just like what’s on the picture? Then rerun your project?

Answered in this thread you posted.

1 Like

Thank you! That worked and I privately message you the next questions

The next question is about navigation, I am trying to navigate from the welcome screen all the way to the end screen. This is my first screen, I’ve tried to do it so many ways but nothing as worked. I don’t mean to sound rude why I say this but please give me in death screens and pictures of my screen for these questions because I am tired of doing this over and over again nothings working

A number of us have tried to point out to you that this particular View will not do anything until you add some logic to your Button action closure to trigger some event to tell SwiftUI that it needs to do something.

Your Button code is currently:

Button("Join") {
   
}

There is no code between the opening brace { and closing brace }

Button("Join") {
    // Add code here to trigger an event to show the next screen.
}

I gave you some examples of how you can navigate or present other Views in this post

Also it is better to paste your code in a reply as text rather than a screenshot so that anyone trying to help you can copy the code from the post and then explain what you need to change and why.

Make sure that when you do paste in your code that you format properly by doing the following:

When you paste in your code, select all of it and then tap the button on the editing bar above where you see the icon </> (Also you can press Command + E which will do the same thing).
This places markers in the post to indicate that you have a code block.

And I did both of those things like you showed me before with adding a code between the opening and closing brace and I also tried it like you said with the third method of navigation, but nothing has worked

I tried it again! And this is the code

import SwiftUI

struct ContentView: View {
    @State private var isShowingWelcomeView = false
    @State private var isShowingAboutUsView = false
    @State private var isShowingEventView = false
    @State private var isShowingMessageView = false
    @State private var isShowingEndView = false
    
    var body: some View {
        NavigationView {
        ZStack {
            Image("birthday")
                .resizable()
                .scaledToFill()
                .edgesIgnoringSafeArea(.all)
            
            
            VStack(alignment: .center) {
                Spacer()
                    Text("Welcome to Smilon!!")
                    .font(.largeTitle)
                    .fontWeight(.bold)
                    .foregroundColor(Color.black)
                    .multilineTextAlignment(.center)
                
                Spacer()
                
                Button("Join") {
                    // Go to AboutUs View
                }
                .padding(.all)
                .shadow(radius: 2)
                .font(.title)
                .foregroundColor(Color.black)
                
                //  Navigate using a Navigation Link
                           NavigationLink(destination: AboutUsView()) {
                               Text("Navigation Link to AboutUs View")
                
             Spacer()
                
                Text("By tapping Join, you agree to our privacy policy")
                    .fontWeight(.bold)
                    .foregroundColor(Color.black)
                    .padding(.all)
                               
                    .navigationTitle("Smilon App")
                                .sheet(isPresented: $isShowingWelcomeView) {
                                    WelcomeView()
                                }
                                .fullScreenCover(isPresented: $isShowingAboutUsView) {
                                    AboutUsView(isShowingAboutUsView: $isShowingAboutUsView)
                                }
        }
    }
            }
            }
        }
        }
 
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

  1. Not sure how I can say this differently so that you will get it this time but: You must put something in your Button's action closure if you expect it to do something. If you aren’t going to be doing anything with the Button, then why is it there? See item 4 below for a suggestion of what you could put there.

  2. Why do you have NavigationLink there if you are trying to use a Button to go to the AboutUsView screen? Use one or the other.

  3. Does your AboutUsView have a property called isShowingAboutUsView? Doesn’t seem like it since you’re getting an error. Do you know why you are trying to pass that value into AboutUsView?

  4. You do not set the values of isShowingWelcomeView or isShowingAboutUsView anywhere, so they will always stay false and those screens will not be shown. Perhaps this is something you should think about putting inside the Button?

  5. Clean up your indents to make your code easier to read (and to make it easier to find things like nesting your preview inside the View). Select your entire file and use ⌃-I (Ctrl-I) to auto-indent the selected code. To illustrate why this is a good idea, I initially thought you still had your preview inside the View because I was thrown off by your wonky indentation.

  6. I will reiterate (and strengthen) the advice I gave you on another thread: I really, really think you need to set this app aside for the time being and try some smaller projects until you understand how navigation works in SwiftUI. Then—and only then—come back to this app with your expanded knowledge. You demonstrate a lack of understanding of the basics of something that is fundamental to SwiftUI and I guarantee you this will only lead to more pain in the future if you don’t take the time to understand it now. I know it’s probably not what you want to hear because you are eager to work on this project, but I think it will benefit you in the long run to do so. (And, in general, it can be very helpful to create small projects to explore new ideas or learn new approaches without screwing up your main project. You can always delete those small projects after you learn what you need to learn from them. Or keep them around as resources for the future.)

Thank you guys for all your help. I have a family friend who can help me, so I am just going to ask him for help

I will get on trying this this and the videos, hopefully I can get it

1)Since I am doing the button to navigate instead of Navigation Link, and I put to go to the about us view between the braces as you said, why isn’t the button working
2)Do I still need all the isShowingAboutUsView stuff if I’m just going to be using the button
3)This is the only thing I am focused on right now, that’s why I am giving my all to it. I just have three things missing

For the purpose of the exercise, create a new SwiftUI App and call it “Test” or whatever you like and paste the following code in place of the code that is currently in ContentView.

import SwiftUI

struct ContentView: View {
    @State private var isShowingAboutUsView = false

    var body: some View {
        NavigationView {
            ZStack {
                Image("birthday")
                    .resizable()
                    .scaledToFill()
                    .edgesIgnoringSafeArea(.all)


                VStack(alignment: .center) {
                    Spacer()
                    Text("Welcome to Smilon!!")
                        .font(.largeTitle)
                        .fontWeight(.bold)
                        .foregroundColor(Color.black)
                        .multilineTextAlignment(.center)

                    Spacer()

                    Button("Join") {
                        // Go to AboutUs View
                        isShowingAboutUsView = true
                    }
                    .padding(.all)
                    .shadow(radius: 2)
                    .font(.title)
                    .foregroundColor(Color.black)

                    Spacer()

                    Text("By tapping Join, you agree to our privacy policy")
                        .fontWeight(.bold)
                        .foregroundColor(Color.black)
                        .padding(.all)

                }
            }
            .navigationTitle("Smilon App")
        }
        .fullScreenCover(isPresented: $isShowingAboutUsView) {
            AboutUsView(isShowingAboutUsView: $isShowingAboutUsView)
        }
    }
}


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

Then create a second SwiftUI View file and name it AboutUsView and replace the contents of that with this code:

import SwiftUI

struct AboutUsView: View {
    @Binding var isShowingAboutUsView: Bool
    var body: some View {
        VStack {
            Spacer()
            Text("About Us View")
            Spacer()
            Button {
                isShowingAboutUsView = false
            } label: {
                ZStack {
                    RoundedRectangle(cornerRadius: 10)
                        .fill(Color.red)
                    Text("Dismiss")
                        .bold()
                        .foregroundColor(.white)

                }
                .frame(width: 260, height: 50)
            }
        }
    }
}

struct AboutUsView_Previews: PreviewProvider {
    static var previews: some View {
        AboutUsView(isShowingAboutUsView: .constant(false))
    }
}

Now have a look at the ContentView code.
Up the top there is a @State property named isShowingAboutUsView and that is set to false as the initial state.

Down the bottom is the .fullScreenCover modifier code. ie:

.fullScreenCover(isPresented: $isShowingAboutUsView) {
    AboutUsView(isShowingAboutUsView: $isShowingAboutUsView)
}

The isPresented parameter requires a Binding boolean value to trigger it so that value in this case is isShowingAboutUsView and the $ sign in front of it designates it as a binding value. The AboutUsView is presented when that binding value is set to true.

So take a look at the code I have placed in the Button closure (between the opening and closing braces { } )
I have set isShowingAboutUsView = true

So when you tap the button “Join”, it triggers the AboutUsView to slide up from the bottom of the screen and cover the current View.

When you tap on the Dismiss button in the AboutUsView, the AboutUsView slides back down and the previous view becomes visible again.

Don’t worry too much about the code in AboutUsView for the moment. I just wanted you to be able to Dismiss that View by tapping on the Dismiss button. What I am trying to get across to you is the mechanics of what you need to do to present another view. It is vital that you understand this concept.

Okay, i’ll test it out tomorrow

I just tried it on the other file I have and it’s kind of working!!

Oh okay, I’m starting to understand it more. I just tested it out and it worked. A couple of things

  1. Is for each screen that I want to show/navigate through, on the previous screen I have to have that code in order for the button to work right?
    2)Is this going to be the file I am now going to use for my app instead of the one I had before, that’s fine if it is then I can just copy and paste what i need over to the new file and we can work through together
    3)Is the content view the same as the welcome view

To be honest with you I think you are far too focussed on trying to create an App for yourself when you really have not gained sufficient knowledge of how to structure an App and how SwiftUI works. I mean it’s great that you want to create your own App but what you need to do first is get a thorough understanding of the Swift programming language and SwiftUI.

It’s taken me years to get where I am in iOS knowledge and I do not claim to be an expert. I’ve learned from many people including Chris Ching, Mark Moeykens, Paul Hudson, Sean Allen and many others who provide tutorials on YouTube.

So I really encourage you to do more courses and tutorials to get really comfortable with SwiftUI because at the moment your questions are on basic things that you need to master before you can even think about creating an App.

As a number of us have said may times, go back over the “14 Day Beginner Challenge (SwiftUI)” course and then do the " iOS Foundations (SwiftUI)" course which covers more complex techniques that you will find very useful in helping you to build your App.

1 Like

Can you please answer my questions?

Do i need to add @State private var isShowingAboutUsView = false part for each screen on the content view