View profile

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

 iOS Code Review
 iOS Code Review
Hi there,
WWDC is coming soon, are you excited? I am, but also looking forward to some vacation time. Not sure yet how much of catching up with the freshest-and-greatest content I’ll do in June, but either way there will be some interesting stuff to share.
Also stay tuned for the next issue #24 on June 1st, it will be a very special one 🤩
Now, let’s dive in 👇

Sizing of SF Symbols
Great thread, nothing to add 😌 Excited to see that Natalia is back to blogging. She posts interesting content regularly, I wish I could feature all of it! Make sure to follow her on Twitter.
Natalia Panferova
A note on working with SF Symbols in SwiftUI: don’t use `resizable()` modifier. Image returned from `resizable()` is no longer a symbol image.

Use `font()` modifier to resize the symbol or `imageScale()` to set the scale relative to the font size.
Natalia Panferova
Documentation for `font()` modifier:

Documentation for `imageScale()` modifier:
Jérôme Alves
@natpanferova Great tip! Could you remind us what are all the issues of the image not being a symbol anymore? I guess it loose dynamic font, maybe some VoiceOver description. Anything else? 🤔
Natalia Panferova
@jegnux You may have some issues with sizing and positioning it properly and it may not work with text nicely.
Automating the encryption compliance check
Definitely makes the life easier. For additional instructions check Complying with Encryption Export Regulations
Daniel Jalkut
Are you an App Store developer who is tired of clicking through the "compliance" question every time you submit a build? There's an Info.plist key for that. WHYYYY doesn't Apple link to this from the compliance question?😱
Comparing date ranges
Since overlaps(_:) is declared on Range and ClosedRange, it can be useful not only for dates, along with contains(_:) (also found as the ~= operator). One can almost forget about comparison operators 😀
Rui Peres
TIL you can in #Swift check if date ranges overlap by creating a close range:

(startDate1 ... endDate1).overlaps(startDate2 ... endDate2)
On dependency injection
Some food for thought on the topic of injecting / resolving dependencies. In this Twitter thread you’ll find interesting points for and against various approaches 👇
Simon B. Støvring
Struggling to figure out what I think about using register/resolve to do dependency injection.

We’re increasing comfort for developers but risking runtime errors. When not using a registry we can make this safe by doing all checks on compile time.

Am I missing something? 🤔
Simon B. Støvring
The @EnvironmentObject in SwiftUI has the exact same problem (via @_nikstar). If a dependency isn’t registered with .environmentObject(_:) prior to accessing it, then the app will crash on runtime.

Do we *really* want this comfort at the price of safety? I don’t know 🤔🤷‍♂️
Starting with unit testing
I wrote a guide to help developers who are motivated to start unit testing their code, but are uncertain about where to begin in practice. Among other things, you’ll find some approaches to picking what to test, and how to start testing seemingly untestable code.
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.

For feedback or sponsorship ->> [email protected]

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.