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
What sort of capabilities that a mutating Swift context has, and what the mutating and nonmutating keywords do.
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
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.
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.
What did you think about these tips? I’d love to hear your thoughts on Twitter via @ios_code_review or over email at firstname.lastname@example.org 🙌