|
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:
So this time i will:
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. =) |
|
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. :) |
|
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 Here's the function:
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:
We can call this function with trailing closure syntax like this:
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 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! :) |
|
|
|
|
|
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! |
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.
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.