@colin@mastodon.cocoasamurai.social
Post #1687790
2026-01-22 01:49 UTC
If an Objective-C API returning an object is mistakenly not annotated as nullable, and returns nil in Swift, is there any way to compare it to nil? Seems like my only option involves UnsafeRawPointer
Replies (3)
-
@mattiem@mastodon.social 2026-01-22 01:59
@colin@mastodon.cocoasamurai.social unsafeBitCast?
-
@bwebster@mastodon.social 2026-01-22 02:23
@colin@mastodon.cocoasamurai.social I think when I came across a similar situation, I wrote my own cover method in an ObjC category that returns a nullable value and call through to the incorrectly annotated method there.
-
@davedelong@mastodon.social 2026-01-22 13:35
@colin@mastodon.cocoasamurai.social manually upcast it to an optional: let foo: Foo? = bar.badlyAnnotatedObjCAPI() Then deal with normally. I do this somewhat regularly