View profile

 Code Review | Curated code improvement tips - Issue #2

 Code Review
 Code Review
Hi there!
Even though it’s summer and many are on vacation, there is no shortage of things that we can learn from our awesome Apple developer community.
I hope you enjoy this week’s findings ☀️🙌

Function annotations for structs
If you write Swift, most likely you use structs a lot. John Sundell goes in depth on how marking functions in structs mutating can help you make code more structured and concise.
Mutating and non-mutating Swift contexts | Swift by Sundell
Handling actions in UIButton
Did you know about UIControl.Event.primaryActionTriggered? It’s been around since iOS 9.0, and it makes touchUpInside obsolete for button action handling. It also makes accidentally picking touchUpOutside and wondering why the button won’t work for an hour less likely. touch* events are still useful for handling touch movements in custom controls, but we can simply use primaryAcitionTriggered in day-to-day. via @_mochs
Michael Ochs
If you make UIButtons focusable and want them to trigger when hitting return, make sure your actions are connected to UIControlEventPrimaryActionTriggered and not to UIControlEventTouchUpInside. Also don’t do this for all buttons. That’s what Full Keyboard Access is for!
On testing and refactoring
Stumbled onto this quote from 2017, and I just had to share it. In my view, this is the best way for us developers to view ourselves as professionals in our field.
“I don’t ask permission to write a test or refactor, any more than I ask for permission to write an if statement or a for loop” - @RonJeffries
Working on multiple branches in git
@rockbruno_ uncovered an awesome git feature: git worktree allows us to check out multiple branches at once in the same repo. git worktree has benefits over cloning multiple copies: you save on disk space (in case your repo has long history) and all worktrees share the same local branches and stashes.
You can use worktrees to have parallel branches checked out long term, f.ex. an older version of the app for comparing functionality, or just to quickly check out coworker’s branch during code review.
Bruno Rocha
Mindblown moment of the day: You can work on multiple branches at the same time with the "git worktree" command. I searched for this because I'm having an issue where the app takes years to build and I can't work on anything else while I wait. Now I can! https://t.co/2sHbe9ofSg
Let's review Copilot's code!
A lot has been said already about Github’s Copilot tool, good and bad. I don’t have access yet, and I’m sure not many of you do. While we wait, let’s review Copilot-suggested code!
How many bugs and improvement opportunities can you find in this piece shared by @krzyzanowskim?
Let me know by filling a one-question form, all anonymous of course. If I get enough replies, I will share most popular ones on our Twitter next week.
Marcin XIV ⛱
copilot can't Swift, and this makes the AI closer to us, humans. We can't Swift either. https://t.co/IukkILg4Sv
✌️
What did you think about these tips? I’d love to hear your thoughts on Twitter via @ios_code_review or over email at ioscodereview@hybridcattt.com 🙌
Did you enjoy this issue? Yes No
 Code Review
 Code Review @ios_code_review

Amplifying code improvement tips from the Apple developer community. Swift, Objective-C, iOS, macOS, SwiftUI, UIKit and more. Curated by Marina Gornostaeva and published every other Thursday.

If you don't want these updates anymore, please unsubscribe here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Created with Revue by Twitter.