Malcolm Hall

  • About
  • Research
  • Consultancy
  • Products
    • AppRecorder
    • Apps Using Location
    • Clipboard Monitor
    • Common Rocks Reference
    • Core Location Info
    • Friendify
    • Grape Stomper
    • HomeMenu
    • iBeacon Scanner
    • Insomnia
    • Navigate from Maps
    • Nickname
    • Plate Smasher
    • Plugged In
    • Readster
    • Resize Image
    • Read★
    • ScreenshotMenu
    • Sleep Display
    • SleepFX
    • Stealth Cam
    • TV Tube Sleep
    • UDID Calculator
    • WiFi Booster
    • WiFi Passwords

SwiftUI, Swift, Objective-C and iOS Development

Concurrency

Converting from @StateObject to .task

To upgrade old Combine code in an ObservableObject that had its lifetime tied to a SwiftUI View using @StateObject we can replace it with .task and since async/await gives us a lifetime like a reference type we can do away Read more…

By malhal, 3 months19th February 2025 ago
Swift

@Observable and didSet

When you mark a class as @Observable you can no longer use didSet because the macro converts it to a computed property, e.g. a simple: When expanded becomes: As you can see test has become a computed property that is Read more…

By malhal, 6 months21st November 2024 ago
SwiftData

Dynamically filtering a SwiftData query

The built-in @Query does not currently support dynamic changes, instead we can use @DynamicQuery from the SwiftDataX open-source package to achieve it. The query declaration looks like this: By default that will load all Prospect model objects, sorting them by name. If Read more…

By malhal, 6 months15th November 2024 ago
SwiftUI

Interesting glitch with Measurement in SwiftUI

SwiftUI’s design takes advantage of equality to decide if things should be updated. Measurement (backed by NSMeasurement) has something interesting in its Equatable implementation: This means that 0kg is equal to 0g despite their unit being different. This makes sense Read more…

By malhal, 7 months30th October 2024 ago
Swift

How to use withObservationTracking to monitor an @Observable

Reposted from: https://forums.swift.org/t/how-to-use-observation-to-actually-observe-changes-to-a-property/67591/18 I thought I’d share an example of how I am currently using it. I wanted to make an object that maintains a sorted order of the main model’s objects. I used withObservationTracking to update if either the sort order Read more…

By malhal, 7 months28th October 2024 ago
AppIntents

How to use SwiftData with AppIntents

I came across this StackOverflow question How do I access the SwiftData container from outside of SwiftUI? but it turns out they needed to use the container inside an AppIntent. I knew the way to inject objects into AppIntents is Read more…

By malhal, 10 months22nd July 2024 ago
SwiftUI

@StateObservable: A property wrapper for using an @Observable class as state without optionals or onAppear

Health warning: In general I would not recommend this approach. View data should be @State simple values or custom structs with mutating func for testable logic, passed down as let for read only, computed vars for transforming, or @Binding var Read more…

By malhal, 12 months21st May 2024 ago
Concurrency

CLMonitor singleton to workaround the “Monitor named is already in use” exception

If you attempt to init another instance of CLMonitor with the same name it crashes with: Since I wanted to use the same monitor from different tasks I needed to turn it into a singleton and came up with this: Read more…

By malhal, 1 year15th May 2024 ago
Concurrency

A simple calculator using @Observable, withObservationTracking and AsyncStream

Following on from my previous post on this topic I found a forum post with someone struggling to build a calculator using @Observable and thought maybe my technique of wrapping withObservationTracking in AsyncStream might help and came up with the Read more…

By malhal, 1 year14th May 2024 ago
Concurrency

Create an AsyncStream from withObservationTracking() function

I needed to create an AsyncStream to monitor changes to an @Observable model class’s var and by using withCheckedContinuation and AsyncStream‘s unfolding init I came up with this: The challenge here is withObservationTracking only watches for a single change but Read more…

By malhal, 1 year4th May 2024 ago

Posts pagination

1 2 … 6 Next
Recent Posts
  • Converting from @StateObject to .task
  • @Observable and didSet
  • Dynamically filtering a SwiftData query
  • Interesting glitch with Measurement in SwiftUI
  • How to use withObservationTracking to monitor an @Observable
Recent Comments
  • SwiftUI 2: the way to open view in new window on Open window / scene in SwiftUI 2.0 on macOS
  • Why Does URL Scheme/onOpenURL In SwiftUI Always Open A New Window? - Programming Questions And Solutions Blog on Open window / scene in SwiftUI 2.0 on macOS
  • Ken Carroll on Enabling iOS 9.3 SDK in Xcode 8 for iOS 10
  • Mr WordPress on Welcome to my Developer Blog
Archives
  • February 2025
  • November 2024
  • October 2024
  • July 2024
  • May 2024
  • April 2024
  • March 2024
  • January 2024
  • December 2023
  • October 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • January 2023
  • November 2022
  • June 2022
  • December 2020
  • May 2018
  • October 2017
  • September 2017
  • August 2017
  • January 2017
  • July 2016
  • May 2016
Categories
  • AppIntents
  • CloudKit
  • Concurrency
  • CoreData
  • CoreLocation
  • Mac
  • MapKit
  • NSOperation
  • Objective-C
  • Swift
  • SwiftData
  • SwiftUI
  • UIKit
  • Uncategorised
  • Xcode
Meta
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
  • About
  • AppRecorder
  • Apps Using Location
  • Clipboard Monitor
  • Common Rocks Reference
  • Consultancy
  • Core Location Info
  • Friendify
  • Grape Stomper
  • HomeMenu
  • iBeacon Scanner
  • Insomnia and Insomnia Pro for iPhone
  • Navigate from Maps
  • Nickname
  • Plate Smasher
  • Plugged In
  • Products
  • Projects
  • Read★
  • Readster
  • Research
  • Resize Image
  • Sample Page
  • ScreenshotMenu
  • Sleep Display
  • SleepFX
  • Stealth Cam
  • TV Tube Sleep
  • UDID Calculator
  • WiFi Booster
  • WiFi Passwords
Hestia | Developed by ThemeIsle