|
Just made my way through this: https://www.hackingwithswift.com/quick-start/beginners/checkpoint-5 Here's what I came up with, not sure if it's entirely correct but seems to get the desired result?
I feel like it reads clean enough and prints out the desired result, is there anything wrong with it I should clean up? Trying to cleanse my mind of doing a decade of PHP and hope it's not infecting the way I'm approaching problems. =P Edit: Actually, please also point out how this should normally be formatted with Swifts typical style. I'm used to stacking calls like that in PHP but haven't seen if that's entirely how you'd line things up normally when writing it. It seemed to be what XCode wanted to do, which is also what I'd normally have done but just thought I'd double check. |
|
@xan is moving at a quick pace and asks for feedback:
You're ahead of the curve, since you already know the basics of programming structure, logic, functions, etc. Nice! You're focusing your attention on more advanced skills that you'd use in a team environment: program structure, style guides, etc. You're on a good path! Perhaps don't worry so much until later lessons. Follow @twoStraw's videos and make mental notes on formatting, etc. Also, you'll pick up good hints in other online tutorials (Karin Prather, Sean Allen, CodeWithChris, CS193p, Rebeloper, Swiftful Thinking, etc). And of course, you've found that out-of-the-box XCode tries to help you with formatting too. Because you already have a decent programming foundation, I'd offer this small comment. Swift was designed to take much of the arcane syntax out (looking at you semi-colons!) allowing much more natural reading syntax. Take advantage of this, and review your own code for clarity. If you and I were having a conversation about playing the lottery, which sounds more like a conversation? First tryObelix: Hey! Lottery is approach 1/2 billion dollars again! Second tryObelix: Splendid! This is an observation about style. So, there is no correct answer. But in a peer review you might get this type of feedback. Keep coding! |
|
Another round of style comments. Often you'll see computed properties, or trailing closures that contain a single line of code. Your example has two:
@twoStraws (and others) often condense these to a single line.
Also, notice how the periods are aligned? This enforces the concept that you've chained three functions together. Again, this is style preferences. So there are no wrong answers. Just very wrong answers. |
|
Ohhh duh that makes perfect sense. Still getting into the habit of one lining things. That does look way better! |
|
Some additional notes: 1.Since your
You also don't need the So your method becomes:
By using the However, Paul's instructions actually say to map the odd numbers to the string
But that seems like an unnecessary extra step to me, since you can just use a |
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.