BT

Compiling Objective-C into C++ with Visual Studio

| by Jonathan Allen Follow 575 Followers on Apr 30, 2015. Estimated reading time: 2 minutes |

While there were rumors that Microsoft would be adopting Android for the Windows 10 platform, no one expected the announcement that iOS applications would also be adopted. This is made possible, by combining C2 with Clang.

Compiler Support

Google and Apple both use Clang for their C++ frontend. In order to make their code run on Windows, Microsoft had to combine Clang with C2, the backend for the Visual C++ compiler.

Apple’s Objective-C also uses Clang for the frontend. So once the Clang was setup for C2, they also gained the ability to parse and compile Objective-C.

IDE Support

Objective-C in Visual Studio has support for syntax highlighting, code completion, and debugging support. C++ and C# files can be included in the same project, allowing programs to directly make calls across the boundary. The compiler will handle all of the marshalling so the developer just sees normal function calls.

Most Objective-C projects will start as XCode projects, so Visual Studio includes the ability to import that project type. The VS and XCode project files can live the folder, allowing you to work in both IDEs on the same project.

Mixed Mode Projects

Windows offers new APIs to Objective-C applications such as Live Tiles. In order to ensure code can continue to be shared between both platforms, Microsoft is offering the ability to use runtime checks to see if the Windows API is available prior to invoking it. Alternately, you can explicitly use preprocessor directives to segregate platform specific code from shared code.

Runtime Behaviors

By default the Objective-C runtime on Windows detects application’s original platform to determine behavior. For example, if you port an iPhone application then it will default to running in a narrow window while an iPad application runs in a normal window.

All of this behavior can be overridden by the application when needed.

iOS API Compatibility

Windows 10 is supporting a “reasonable subset” of the iOS APIs. It does not track a particular version of iOS, but instead looks at metrics to see which APIs are most commonly used. For the first version, the APIs Microsoft focused on include:

  • Games: OpenGL, OpenAL, and Sensors are well supported.
  • UI: UIKit, CoreAnimation, CoreGraphics, CoreText, Touch
  • Objective-C: ARC, Blocks, Foundation

For features such as share, notifications, and StoreKit, developers need to choose between keeping the iOS APIs or switching to the Windows alternative. If you keep the iOS APIs, Windows will provide a compatibility layer so that the APIs will just work. The benefit of switching is that you gain access to advanced Windows features.

Swift

Microsoft’s official stance on Swift is “No comment at this time”. Unofficially, they want to support it but are currently too busy working on getting Objective-C ready for the fall to dedicate resources for Swift.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT