Post

Replies

Boosts

Views

Activity

Reply to Associated Code?
actor ImageDownloader { private enum CacheEntry { case inProgress(Task.Handle<Image, Error>) case ready(Image) } private var cache: [URL: CacheEntry] = [:] func image(from url: URL) async throws -> Image? { if let cached = cache[url] { switch cached { case .ready(let image): return image case .inProgress(let handle): return try await handle.get() } } let handle = async { try await downloadImage(from: url) } cache[url] = .inProgress(handle) do { let image = try await handle.get() cache[url] = .ready(image) return image } catch { cache[url] = nil throw error } } }
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to AsyncPublisher of KeyValueObservingPublisher doesn't work
This appears to be a bug in NSObject.KeyValueObservingPublisher. It's triggered because the values property only sends an initial Demand of .max(1) when it subscribes to the KVO publisher. Forcing a larger Demand works around the problem. We can use the handleEvents operator to send unlimited demand to the KVO publisher: Task { for await value in obj .publisher(for: \.count) .handleEvents(receiveSubscription: { $0.request(.unlimited) }) .values { print("async: \(value)") } }
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’24
Reply to Associated Code?
actor ImageDownloader { private enum CacheEntry { case inProgress(Task.Handle<Image, Error>) case ready(Image) } private var cache: [URL: CacheEntry] = [:] func image(from url: URL) async throws -> Image? { if let cached = cache[url] { switch cached { case .ready(let image): return image case .inProgress(let handle): return try await handle.get() } } let handle = async { try await downloadImage(from: url) } cache[url] = .inProgress(handle) do { let image = try await handle.get() cache[url] = .ready(image) return image } catch { cache[url] = nil throw error } } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to "dyld: Symbol not found" crash when I run my app using Xcode 14 because can't find CGRect.divided(...)
This appears to be fixed in Xcode 14.0 beta 2. I had to clean my build folder for it to start working though.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to How to display stereo images in Apple Vision Pro?
Using Reality Composer Pro, you can make a custom material that feeds the left and right images into a GeometrySwitchCameraIndexNode.
Topic: Spatial Computing SubTopic: General Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to How to handle having more than 10 WindowGroups and ImmersiveSpaces?
Use Group, with no more than 10 direct children in each Group. https://developer.apple.com/forums/thread/740677
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’24
Reply to AsyncPublisher of KeyValueObservingPublisher doesn't work
This appears to be a bug in NSObject.KeyValueObservingPublisher. It's triggered because the values property only sends an initial Demand of .max(1) when it subscribes to the KVO publisher. Forcing a larger Demand works around the problem. We can use the handleEvents operator to send unlimited demand to the KVO publisher: Task { for await value in obj .publisher(for: \.count) .handleEvents(receiveSubscription: { $0.request(.unlimited) }) .values { print("async: \(value)") } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Feb ’24