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

SOLVED: Checkpoint 4 - Stuck!

Forums > 100 Days of SwiftUI

Hi all,

I'm doing 100 Days of SwiftUI and I'm stuck at Checkpoint 4. I don't know how long I sat in front of my laptop trying to find a starting point. No matter what I wrote, I felt like I had my back against the wall and just deleted everything and tried starting anew. Eventually I got so frustrated I just quit. But that does not mean I'm giving up! I'm going to try again tomorrow. But right now I'm feeling completely paralyzed. Maybe it's because I had a very rough day in general but I also feel like I'm not able to utilize most of what I've learned so far.

Could anyone point me in the right direction? Which topics should I maybe revisit and rehearse?

I have very little programming experience. The most advanced thing I've programmed before starting this course was a unit converter written in Java way back in 2009.

Thanks for any help! :) Loving the course so far but sometimes this programming stuff really makes my head spin...

3      

Welcome to Checkpoint 4!

You say you have very little programming experience. But a lot of programming is puzzle solving. First, think of the steps you'd take on paper to solve this problem.

Write out the steps as if you were explaining the step-by-step solution to a summer intern.

GOAL: Find a square root of a number, where that number is between 1 and 10_000.

  1. Get a number from the user.

  2. Verify the number is greater than 0 AND less than 10_001.

  3. Start with a 1.

  4. Multiply that number by itself. (1 x 1 = 1, 2 * 2 = 4.... etc)

  5. Does this answer equal the number you got in step 1?

  6. Yes? Well done. Print your results!

  7. No! Is the result less than the number from step 1?

    7.a Yes! Ok, add 1 to the number in step 3. And run steps 4 and 5 again.

    7.b No. If the result is greater than the number from step 1. You won't find an answer. Print your finding.

  8. STOP.

More or less, this is a logic problem. When you get stuck with a programming problem, stop programming! Instead get out paper and pencil and attack the problem from a logic standpoint.

Then start building your Swift solution one line at at time.

  • Step 1: SwiftUI Form, TextField.
  • Step 2: Swift IF statement.
  • Step 3: variable assignment
  • Step 4: maths
  • Step 5: If statement
  • Step 6: SwiftUI Text()
  • Step 7: If statement
  • Step 7a: for...loop
  • Step 7b: function return statement
  • Step 8: End of function / program

5      

That is actually very helpful. Thank you. Due to a neurological condition I have problems with executive functioning so my brain often has trouble parsing big tasks into smaller subtasks. That's also one of the reasons I decided to learn programming. It strengthens the frontal lobe and a strong frontal lobe is good for your executive functioning. :)

I'll try to compartmentalize the problem on paper tomorrow.

3      

After a day of struggling I got it working. After having a working function without syntax errors, I exhaustively tested that the square root is calculated correctly and all error cases are thrown (and later catched) as instructed. It's not a pretty piece of code but at least it works.

My biggest struggle was with the for loop doing the calculation as I constantly got lost in the various conditional clauses and messed up the closures. And I had a hard time understanding how to do the calculation.

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.