Monday, March 5, 2018 [Tweets] [Favorites]

First-Class Swift API for Objective-C Frameworks

Marcin Krzyżanowski:

In Objective-C, it’s possible to store a block as an id type, e.g. in a collection like NSDictionary<String *, id>. However, that’s a trap. If we store a Swift closure in the imported dictionary type, it will crash at the time we access the value.

There is a workaround, but it has to be done on the Swift side. Declare the closure type with the @convention(block) and use it as a type[…]

[…]

The non-system framework Objective-C NSUInteger is imported as UInt. That’s not very consistent with the Swift concept of having an Int as the ultimate integer type. The conversation about if NSUInteger should be automatically imported as an Int is already older than a year, and we’re still looking for a better solution in this area.

[…]

API Notes is a textual file with a set of metadata interpreted by Swift’s Clang Importer without the need to rebuild the binary.

[…]

@_exported will make an imported module re-exported as if the imported symbols were part of the intermediate module. The intermediate module is logically placed between two other modules, which is why it’s called an overlay framework: It overlays the @_exported modules.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment