Hacker News new | ask | show | jobs
by mayoff 3630 days ago
Almost all Objective-C APIs can be accessed from Swift. (The one exception I know of is that a type which is a class with protocol conformances, e.g. `UIViewController<UIPickerViewDataSource>`, cannot be represented exactly in Swift. You can still use APIs with such a type, but the type will be different in Swift.) So if you implement your API in Objective-C, you're guaranteed that it's usable in Swift (though perhaps not idiomatically).

There are multiple Swift constructs that cannot be exposed to Objective-C, such as enums with associated values, structs, and global variables and functions. So if you implement your API in Swift, you have to be careful if you want it to be usable from Objective-C.

Another problem with writing your API in Swift is that the Swift ABI isn't stable yet. It changes between compiler versions. This means that your API (if written in Swift) must be compiled with the same Swift compiler as the user's code. If you want to distribute your API as a binary-only library, you'll have to release a new version every time Apple releases a new version of Xcode, and your user will have to be sure to get the correct version of your library for their version of Xcode.

1 comments

> The one exception I know of is that a type which is a class with protocol conformances, e.g. `UIViewController<UIPickerViewDataSource>`, cannot be represented exactly in Swift

Sort of doable with generics, but only from Swift code:

    <ViewController: UIViewController where ViewController: UIPickerViewDataSource>