Re: Need for Swift
Re: Need for Swift
- Subject: Re: Need for Swift
- From: Jens Alfke via Cocoa-dev <email@hidden>
- Date: Tue, 15 Oct 2019 09:52:08 -0700
> On Oct 15, 2019, at 9:40 AM, Richard Charles via Cocoa-dev
> <email@hidden> wrote:
>
> 2. Another option is Swift but it has zero integration with C++. So this is
> really not a choice at all.
Swift integrates with C. So you can declare C APIs to your C++ codebase, and
call those from Swift. This does mean writing a lot of C++ wrapper code in the
form of extern "C" functions that call your C++ methods. Which is admittedly
extra work, but hardly rocket science.
For context: I work on a database library[1] implemented in C++ that provides
exactly such a C API, which is then used by higher-layer frameworks written in
Objective-C, Swift, Java, and C#. So I know this works and is not an
unreasonable amount of work. Here [2] is an example source file if you want to
see what it looks like. (Note that some of the boilerplate is to catch
exceptions thrown by the C++ layer; if your C++ doesn't use exceptions, you
don't need that.)
—Jens
[1]: https://github.com/couchbase/couchbase-lite-core
[2]:
https://github.com/couchbase/couchbase-lite-core/blob/master/C/c4DocExpiration.cc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden