2 min read

Issue #21

Hi there,

Hope you're safe, wherever you are. I'm excited to share this week's findings with you!

This time I'm doing something new in addition to the usual tips. The pandemic has been hash on the conference scene, and the next conference season is coming up. I figured I'd highlight some conferences that are still looking for speakers.

Enjoy! ☀️


MainActor.run vs @MainActor

You can dispatch a Task to the main actor two ways - by explicitly calling MainActor.run or by annotating the closure with @MainActor. These two ways have different behaviour. If already on the main thread, the former will run immediately but the latter will run on the next runloop cycle. Find detailed explanation in this article by Paul Hudson.

Synchronizing user defaults

Since iOS 12, the synchronize() method on UserDefaults does nothing, and we don't need to call it anymore. It's interesting that the method is not marked as deprecated yet. Here's a quote from the release notes for iOS 12:

Removed synchronization requirements. It’s no longer necessary to use synchronize(), CFPreferencesAppSynchronize(:), or CFPreferencesSynchronize(:::). These methods will be deprecated in a future version of the OS. Now that you don’t need to call these synchronization methods, the performance characteristics of UserDefaultsand Preferences Utilities are slightly different: The time taken for enqueueing write operations is now paid by the writing thread, rather than by the next thread to call synchronize() or do a read operation.

Codable in Firebase

There's now built-in Codable support in Firebase, so there's no need to bring in additional packages such as CodableFirebase. Now you can simply write: ref.getDocument(as: Book.self) {...}. The type just needs to have a property annotated with @DocumentID property wrapper, so the framework knows which property is the identifier. If you want to learn more, Peter also wrote a comprehensive guide.

On refactoring

Wise words here. If one commit contains both refactoring and behaviour change, if things break (or, when) it'll be hard to tell whether they broke due to refactoring or due to a bug in new behaviour. I split these up, always.

Also sometimes people call any change in code structure a refactoring. Here's a quote from Wikipedia: "code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior."

CloudKit

Did you know that apps using iCloud (CloudKit) cannot be transferred to another account? This means that selling an app with CloudKit can be a tricky endeavour - with the only option being to sell the whole developer account.

iCloud red flag for indie developers

As a consumer, I love iCloud. One central storage for documents, photos and app data. What's not to love? As a developer, I'm much more wary.

Conference time!

This time I want to help the community by highlighting some of the upcoming conferences.

CFP (call for papers) is a format when potential speakers submit their talk ideas. If you've been dreaming about giving a talk - this is your hint to finally go for it 🤘

Looking for speakers

New kid on the block

  • plSwift - A brand-new Swift/iOS conference in Wrocław, Poland. 25-26 May 2022. plswift.com

☮️

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 🙌