I'm looking for some constructive criticism please. Although I added a little on my own this time for fun, my code always seems more verbose than others. Would love some thoughts on how to make things more efficient or the general idea that I am ok with how things are being done.
Your code is verbose because your logic is verbose! A cursory look at your solution leads me to think that you have a background in procedural languages (VisualBasic, C++, JAVA, etc) and haven't quite made the jump to SwiftUI's declarative style.
The good news is that you're learning! The better news is as you gain experience, you'll start to see some inefficiencies and your code will get better and less verbose. It will become more Swifty.
Well you asked for thoughts, and not a lecture. So here are a few to get you started.
Ten points to Ravenclaw for using MARK tags in your code!
Minus ten points from Ravenclaw for naming your view
You declare your structs variables like this:
Moving forward, trust the
You'll start to learn the benefits of calculated properties as you progress. This is a great way to consolidate your logic while reducing code. Take this use case for example: When do you want to end a game?
You have this code:
This is referenced in several places in your code, tied to some value (10). It has to be set and reset. This is verbose, and can lead to logic errors trying to keep these syncronized.
The Swift way is to declare it!
Instead of scattering logic throughout your code, consider the benefit of asking Swift to calculate if your player is at the end of a game.
This allows you to simplify your logic in your
Nota Bene: It is no secret that SwiftUI's declarative style is copied from many other languages. Hush now.
Phenomenal answer. This is exactly what I was looking forward and very much appreciated.
I did move to Swift/SwiftUI from VB and C++ (a little bit of HTML and Java) and am really enjoying this learning experience.
Thank you again for the review. I will look to use this for future lessons/projects.
I agree with
Also going on general put
as this is the
With that it a bit big so you could factor it out.
I started with the first bit of the
NOTE change your Fonts size to use general one as these will size up and down depanding on thier size perference.
Next look at the the next section. (you put them in
Next looked at
Also look at the the starting properties and your put
(I have used
and change your
Lastly moved to ViewModel, so created a Swift file called
So now the
Thanks @NigelGee. Excellent information and much appreciated.
Admittedly, some of your answer is a beyond my current skill-set (Day 25) but I fully understand the concepts you are showing and feel good about that.
This will really help me moving forward in the 100 Day course.
Glad you appreciated the answer, when I started I was only going to suggest to refactor the
SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.
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.