Pop quiz! What is the output of this program, e.g. when run in a playground or an autoclosure block? The documentation indicates as much, but it can still be a surprise in your programs when you treat the @Published
event as a mere signal to read multiple values from the observed object.
Continue reading …
Here is a transaction type to copy & paste into projects to encapsulates thread-safe read/write access: Just make sure to not use the main queue, because .sync
call from main to main will deadlock your app! It ensures you read values synchronously, which isn’t dangerous, and enqueue and execute write operations in order. This is useful if you need to access any resource from multiple threads and want to avoid the overhead of mutex locks.
Continue reading …
I really want to like Swift property wrappers for UserDefaults
. But I have a hard time making them 100% useful. Take the post by Andy Ibanez on the topic for example. It’s a well-written post with great code examples. If you want copy-able code for your app, read it. It’s good.
Continue reading …