Tuesday, May 31, 2016

Swifty Objective-C

Peter Steinberger, Michael Ochs, and Matej Bukovinski:

Using Swift without binary compatibility would mean that we have to offload technical details to our customers and restrict them in their choice of Xcode to a point where they might not be able to update to Xcode 7.3.1 if our SDK is still compiled with 7.3.0.

[…]

Instead we decided to use Objective-C++ to complement pure Objective-C where appropriate. […] In our Objective-C classes, we only use a very tiny amount of C++ to benefit from the convenience, safety, and performance features of C++. In contrast to full blown C++ implementations, learning a small subset for use in a mainly Objective-C codebase is very easy, even for developers without any prior C++ experience.

[…]

When using generics it gets quite annoying to type the type specifier […] auto will transform at compile time to the above — it doesn’t require any runtime features.

[…]

In Objective-C NSArray can only contain objects. This is both more complicated and — because of boxing — slower for primitive types. […] With Objective-C++ we can simply use std::vector:

[…]

The C++ lock is automatically released when it goes out of scope. The RAII pattern is everywhere in C++ and it’s really great and deterministic. This allows us to do work that requires locking inline with a return statement as the lock is only unlocked after the return.

[…]

Compiling .mm files will take a bit longer than standard .m files, however in our experience it’s worth the slight compile time penalty.

1 Comment RSS · Twitter


[…] Swifty Objective-C, foreach Using Objective-C […]

Leave a Comment