|
Hello everyone again I'm struggling with Day 35 and one of the things I'd like to understand is - How to switch between the views ? I tried to make a simple layout to check this "Manual" way of switching (using closures as Paul noted in challange requirements) but it doen't work. Very simple idea : We have a plain screen with MainView, where we have a But it doesn't work somehow. I tap on Button and no response. So would you mind to give hint what am I missing ? Big thaks ! p.s. I know later I will discover advanced approaches , but for now I'd like to understand how to make this in a "manual" "stupid" way.
|
|
|
|
@Bnerd thanks for reply and your suggestion! Am I mistaken but I don't think If it works, sure I can try and use it. But I'd like to know how to do this with It's great to know more advanced techniques but I'd like to know "simple/primitive" solution too. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
Correct me if I am wrong but the challenge in Day 35, requires you to break down your view to smaller views, not navigation. Am I missing something? What he meant is that instead of having a 100 lines contentview, you can create separate smaller views and call them within your content view. |
|
@Bnerd , maybe I didn't get it right, I won't argue. I took it as: a part of the challange is to make separate Views instead of making everything in one, default "ContentView" page . And in theory for that you need more Structs which represent separate views : / Isn't it ? |
|
You can still make separate Views in separate files :) Making the view in a separate file or making the view in a struct below your content view struct is the same thing! |
|
The reason your button isn't working is because it simply calls the initializer You will learn many ways of showing additional views in future projects. But for this project, I used a VStack with of couple of
(I just tested and in the latest version of XCode I was actually able to remove the ZStack and use an if/else statement instead of 2 if statements. I don't think that I was able to do that when I first created the project for some reason though.) |
|
@FlyOstrich, thanks man! Actually, it's because of you I created this topic. I was looking for help with solutions for day 35 Challenge and I've found only 2 topics with enough amount of code to make my brains undestand something. One of them was your's. Even though it was not a full code for the working( you managed to get this option with changing views through functions with the help of @GreenAmber if I'm not mistaken) app I still could take something from your efforts. And here I wanted to clarify that option but as we can see not a lot of people willing to make a contribution. That's ok, no one owe anything to anyone. Now I know that important part in that "technique" was usage of Boolean condition and if/else. They've been making all that stuff work ! And now you confirmed that in your reply. I appreciate ! I know already about NavigationLink. As you say there will be other methods. But it's never bad to know a little more I guess. Especially when a super slow guy like me tries to achieve success in programming but it's still super difficult and confusing and I'm constantly in 1 step to give up with a thought: "What's the point to continue if I already struggle with solutions being at the beginning of this course? And it's gonna be even more complicated and confusing later with every day". p.s. The other guy was the only one to show here his full working solution code made in 1 single View. And guess what ? - No one even commented his great job and efforts. Topic was completely ignored and left without replies. I felt shame he didn't get even a drop of attention. |
|
Well, I think people usually try to avoid showing the full finished code for their projects in these forums because if you just give away all the answers, it doesn't give other people a chance to actually learn for themselves rather than just copy/paste some code. However, sometimes it can be helpful to see the answer in order to study it and solidify your understanding of something. So, it is a fine line to dance along. Some people look at these forums every day, and try to answer everyone that they can. Some people only stop by once per week, or maybe less often. So it can sometimes take a long time to get answers to your questions that you are looking for. You also have to remember that most of the people who do look at these forums are people who are currently working their way through the 100 days course themselves. So, they may not feel confident enough in their own knowledge of the subjects to be able to provide answers to other people's questions. I try to answer questions when I feel confident enough about my answers to help someone. But I don't always know the answers myself. But, I wouldn't give up just because you are struggling with what you are learning right now. You've already made it 1/3 of the way through the course at least. Plus, the more you learn, the easier it becomes to progress with the future projects. Don't feel too bad about yourself if it takes you more than one day to complete 1 day of course material either. I have often spent multiple days on trying to make sure I fully understand something in this course. (Especially on the challenge days.) |
|
@ngknm14, OK so just for what you said , a plain simple way to present a new View
|
|
I like to think of small chunks of view code as Lego bricks. Once you create a sweet, reusable Lego brick you can reuse it several places in your code. But soon enough, you'll be reusing the brick in other applications. See -> Using Lego to Develop Views |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.