Post

Replies

Boosts

Views

Activity

Reply to If NSImage is not Sendable, how should async functions return images?
@Polyphonic: Thanks for the reply. I understand what @unchecked Sendable means and I agree that this would mean that NSImage is Sendable – but the thing that prompted this question was that the extension is marked as unavailable on all platforms and versions (because of the *). So what does it mean when a class conforms to a protocol in an unavailable extension? The following experiments use “Complete” for SWIFT_STRICT_CONCURRENCY: Xcode 14, macOS 13 SDK, macOS 13 Deployment Target I tried returning an NSImage from an async top-level method and that gives me this warning: Xcode 15, macOS 14 SDK, macOS 14 Deployment Target The same code compiles without the hint at the import Cocoa line, which I would interpret to mean that the macOS 14 SDK has been fully audited for Sendability and suppressing the warnings isn’t an option anymore (not that I would want to do that): Just to make sure, I also tried it with an actor: So the compiler definitely does know that NSImage is not Sendable, which means the availability annotation in that extension I originally mentioned does not add Sendability conformance but instead seems to document the opposite. This can also be verified by adding the following (unwise) extension to the code in the screenshots, which “fixes” the warning: extension NSImage: @unchecked Sendable {}
Topic: UI Frameworks SubTopic: AppKit Tags:
Aug ’23
Reply to Is it possible to `repeat` statements that do not reference a parameter pack?
Oh, you’re right, my code doesn’t compile due to the duplicate generic parameter name T. Sorry about that. And yes, what you wrote is pretty much where I intended to end up. Weirdly enough, it doesn’t compile, though, and all I get is a nondescript “Command SwiftCompile failed with a nonzero exit code” 😕 In my actual code where I stumbled across this, it does compile, though. I tried but I couldn’t manage to get my sample code (or yours) to compile… FWIW, here’s my actual code: /// Adds a side effect that is performed whenever any of the tweaks’ value changes. @discardableResult public static func addSideEffect<each Value>(to tweak: repeat Tweak<each Value>, sideEffect: @escaping () -> Void) -> (repeat Tweak<each Value>.SideEffectID) { func add<V>(to tweak: Tweak<V>) -> CustomSideEffect.ID { let sideEffect = CustomSideEffect(action: sideEffect) tweak.tweaks.store.sideEffectPerformer.add(.custom(sideEffect), for: tweak.id) return sideEffect.id } return (repeat add(to: each tweak)) }
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’23
Reply to Can a function with parameter packs return a non-generic value for each parameter?
Of course I found the solution immediately after posting this 🤦‍♂️ The trick is to get the parameter pack into the return value somehow. I did it using a typealias inside the generic type: struct Tweak<Value> { typealias Name = String var name: Name var value: Value } func names<each Value>(of tweak: repeat Tweak<each Value>) -> (repeat Tweak<each Value>.Name) { return (repeat (each tweak).name) } And now it works as it should 🙂
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’23