View profile

 iOS Code Review | Curated code improvement tips - Issue #15

 iOS Code Review
 iOS Code Review
Hi there,
Hope your Thursday is going the way you want it to go 🌟 Let’s dive into this week’s highlights!

On mixing Swift and ObjC
Adding a shim layer is a great way to approach moving to Swift in an Objective-C codebase. I can confirm from hands-on experience practicing it successfully on large ObjC projects.
I had this tweet saved in bookmarks for a while, thinking maybe I’ll write an article on it some day. But no need anymore - Steve himself just published a great article going deeper on this topic. Huzza! Here’s the full article: An Approach for Migrating From Objective-C to Swift
Steve Barnegren
@stroughtonsmith Rather than build ObjC compatible Swift, build idiomatic Swift and create ObjC shims. As you replace the ObjC you can remove the shims.
Golden path
Wikipedia describes golden (happy) path as a default scenario featuring no exceptional or error conditions. Swift sure took it to heart by introducing the guard statement. If you are not using it actively yet, maybe this is your sign 😀
Brandon Levasseur
@twannl There’s a long living rule called “The Golden Path” that inspired the introduction of the `guard` statement in Swift. Ultimately, my argument will always be if you can avoid an `if` statement, you should and encourage “The Golden Path” for readability, clear functional exists,etc
Greg Ellis 
Swift coding tip of the day 💡
Avoid deeply nested Swift code

Two functions that do the same thing, but first one much cleaner and easier to understand. ✅ https://t.co/WW2h0q2C4r
@discardableResult
@discardableResult is the proper way to silence the unused variable warning:
 Jaafar Barek
💡 Swift Tip:

If you have a function that has a return value, but in some scenarios you want to ignore it.

You can use "@discardableResult" to avoid warnings or the usage of _

Example:

#iOS #Swift #iosdev #programming #development https://t.co/YVsjfJCKSH
Lazy variables are not thread safe
Antoine explains how to avoid data races with lazy variables in this section: How to solve a data race. TL;DR: you can either make all operations with the variable on the same thread, or use actors - the new feature in Swift.
Antoine v.d. SwiftLee 
A great benefit of blogging: learning new stuff yourself.

For example, I've learned that a lazy variable can cause Data Races quite easily 🤯

Let me explain it to you:
https://t.co/Aad1ytEHEt

#swiftlang #iosdev https://t.co/Kyzg5jxmY7
Spell check in comments
Did you know that Xcode has a built-in spellchecker for comments? That’s been introduced in Xcode 11. I think it’s strange that it’s not enabled by default. @felibe444 wrote a quick guide on how to turn it on: Typos in Xcode – Never Again!
Feli #DieHimmelstraeumerin
It seems to be a classic that can't be talked about enough! There's a setting in Xcode that checks spelling and grammar for you and makes you aware of typos.
It's one of my favorite settings and I need it more often than I'd like to admit 😅

https://t.co/6eNYXa08xL
HIG for text
Made by @k_katsumi, Apple Localization Terms Glossary is a handy reference point for text in your app. You can easily refer to texts that Apple uses in their UI, as well as see corresponding localisations to other languages.
Another great resource in this area is Apple Style Guide, the official glossary of how to use certain terms. It’s like Human Interface Guidelines but for text - definitely worth checking out.
Apple Localization Terms Glossary
‎Apple Style Guide on Apple Books
🤘
Alright, that’s it for today. 
Did you enjoy this issue? Let me know by pressing the buttons below, so I can improve the newsletter. 
Got feedback? Want to see more, or less of certain kinds of tips? I’d love to hear from you. Reply to this email or reach out on Twitter via @ios_code_review 🙌
Did you enjoy this issue? Yes No
 iOS Code Review
 iOS Code Review @ios_code_review

Bi-weekly newsletter amplifying code improvement tips from the Apple developer community in a bite-sized format. Swift, Objective-C, iOS, macOS, SwiftUI, UIKit and more. Curated by Marina Gornostaeva and published every other Thursday.

In order to unsubscribe, click here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Created with Revue by Twitter.