View profile

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

 iOS Code Review
 iOS Code Review
Hi there,
Hope you had a wonderful WWDC week! I myself have been on vacation (and still am), and only checked out the keynote and saw some tweets from the community.
Other newsletters have featured lots of WWDC-related articles - for example I loved the latest iOS Dev Weekly which was 100% about WWDC.
I tend to forget all the new things by the time I can use them for real, so I’ll be featuring more of the new APIs after Xcode 14 ships in September. My goal has always been to share things that can be used right away in real projects (gotta be honest it’s also convenient because I could continue spending the vacation offline 😋)
I was also interviewed on the AppForce1 podcast, where I shared a bit about how I make the newsletter ☺️
Now let’s dive in!

#unavailable attribute
The new #unavailable attribute has been added in Swift 5.6 (Xcode 13.3) - we can now check for older OS versions directly:
if #unavailable(iOS 15.0) { /* this code will run on iOS 14 and below */ }
Antoine v.d. SwiftLee 
Swift got a new feature too, which I really like! No more if # available(iOS 14.0) { } else statements!
Dealing with SwiftUI type inference
Do you sometimes try to write f.ex. Color.background, only to have nothing come up in autocomplete? The issue is that .background exists, just not on Color - it’s a separate shape style, and the shorthand is only available by the magic of type inference. Jérôme here shares an approach for finding what you’re looking for (see series of pictures in the full tweet)
Jérôme Alves
SwiftUI Pro Tip: If you don’t find something (ex: Color.background), don’t assume it doesn’t exist yet. Check conformances of the type you are looking for (ex: Color) for the abstraction. Then check the abstraction’s conforming types to find the good type.
Unit tests eh?
Tony Dinh 🎯
Pros and Cons of writing unit tests:

Pros: unit tests
Cons: writing
in all seriousness though:
Manuel Schulze
🧪I love tests. I think many #iOSDev s see them as just a way of knowing that your code works. But it's more than that.
- You know it still does work after changes in the future
- You know that your code is written in a way that can be tested
- You have a form of documentation
@rickycpadilla Depending on the domain you are working in unit test using TDD can be extremely helpful. If I am working in unfamiliar domain I personally always write domain level unit test. But tests have nothing to do with the success of app. It does gives you confidence to make future change
The new thing is out
Eternal wisdom from Jordan, now more relevant than ever before:
Jordan Morgan
I just learned RXSwift!

— Oh no, Combine is out! —

I just learned Combine!

— Oh no, Async Sequence is here! —

Hold up, if you’ve got an architecture that works for your app, keep using it. You probably only need to be *aware* of new things, not drop what’s already working.
Moving the cursor in terminal
Okay this is not a code thing per se, but this terminal key binding has been a nice time saver for me since I learned it a couple of years ago:
Random dev tip:

On your terminal, to move the cursor to any exact point you want, simply use OPTION + Click.
No more long-pressing the left/right arrow keys.

Happy coding 😁
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.