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

A new round of 100 days of SwiftUI

Forums > 100 Days of SwiftUI

Hello there,

<p> <p>I recently finished working through the "100 days of SwiftUI" course and i do believe i have learned alot. However, i do not, at all, feel like i have the basics covered and i have not wrapped my mind around the concepts and problems presented by Paul in this course. <p> I WILL learn to code, no matter how long it takes, so i will do this course one more time, but doing it alot more organized from my part.

I will use this topic as my billboard where i post my thoughts and what i learn, anyone is free to chip in, but really, im doing it for myself. Because, when you write anything down you really have to think about it first, which for me is a big part of learning.

Some of the errors i made during the course was:

  • Not learning the concepts thoroughly
  • It took me around 6 months to complete the course, with some, quite long breaks in there, which made me forget alot.
  • Not being engaged enough during the course

So this time i will:

  • Have this topic as my billboard of thoughts, questions and also for accountabillity
  • Write down questions during the lessons and make sure i really understand whats going on, whether its syntax, concepts or something else.
  • Something i learned aswell is that the 1 lesson a day concept does not work for me. I really like getting my head into something, and iv got quite some time on my hand at the moment so i will do everything by my own schedule.
  • I will also have a notebook by my side to write down some small tips Paul gives during the lessons that will be usefull for the app i want to build in the end.
  • I will also use the "Swift Language Guide" for reading about the specific subjects Paul is teaching
  • Have a large stock of coffe!

If anyone has any tips, experiences or suggestions regarding learning or coding i will gladly read them.

This topic will be updated regularly. Also, please excuse my English, it's not my native language. =)

1      

So the last week i completed Day 1 too day 9. What i have gathered so far is that its functions, closures and syntax i have been having troubles with during my last round.

If i have understood it correctly, instead of passing a function into another function you pass in a closure instead, mostly used in SwiftUI. However you can create a closure directly into a constant or variable which makes some work you want to be done short and consise. You can also create a trailing closure that gets passed into a function when some work is finished.

Closures are defined as: "Self-contained blocks of code that can be passed around and used in your code." in the "Swift Programming Language Guide". They may make it easier to understand.

Also, trailing closure syntax is really no joke, if someone knows another explanation that might help or a trail of thought that makes it easier to understand, that would be appreciated. :)

1      

I don't know exactly what you would like to clarify with trailing closure syntax, but I really like it because it can read like English.

I think Paul Hudson's article about why Swift has trailing closures captures why they can be so nice to work with.

In this article, he writes out a function that accepts a Double and a closure that takes nothing and returns nothing (so, the type would be () -> Void... this can also be written as () -> () but the former is less confusing).

Here's the function:

func animate(duration: Double, animations: () -> Void) {
  print("Starting a \(duration) second animation...")
  animations()
}

We have two ways to call this function since the function accepts a closure.

We can call the function without trailing closure syntax like this:

animate(duration: 3, animations: {
  print("Fade out the image.")
})

We can call this function with trailing closure syntax like this:

animate(duration: 3) {
  print("Fade out the image.")
}

Trailing closure syntax is not required, but it's really just a way to make your code a lot cleaner to work with. In the function call without the trailing closure syntax, we're directly passing in a closure that prints, "Fade out the image." In the function call with trailing closure syntax, we're doing the exact same thing, except that it just looks a little bit more organized. The code in between the braces is the actual closure that you're passing into the second parameter.

You can read it like English because you could say, "This function will animate for a duration of 3 and then print out a message." It's called trailing closure syntax because the closure you pass in "trails" the rest of the function call, as it's at the end.

Remember, you can only pass in a closure to this function that will take nothing and return nothing, as specified by the function definition at the very top. We stated that the function will take a closure that is of type () -> Void.

So, trailing closure syntax is really in the name — it's just (what I think is clearer) syntax that allows a closure to be "trailing" at the end of a function call. Just a small tip, you need to accept your closure(s) at the end of a function definition in order to use trailing closure syntax... otherwise they wouldn't be "trailing" at all.

I hope this helped! :)

1      

Ah i see! Thanks for the reply! This helped! =)

2      

Awesome! :)

1      

Finished the first 15 days, albeit a little later than i thought, but hey its summer time and other things call for attention. This time i didnt have so much difficulties with anything. The most brain twisting was the protocols and the protocol extensions but i got the hang of them after a while. Looking forward to build the projects one more time and now i will really try to identify the different concepts and what is what when coding, this way i believe i will understand it better and thus learn better.

Ahoy!

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.