Making use of existing iOS code

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

Speed up development time by re-using your existing iOS code.

If you are porting an application from iOS to Windows 8.1 or Windows Phone 8.1, it would be nice if you could re-use the code you spent so much time getting right. Unfortunately, there's no easy way to move your code base from Swift or Objective-C to C# (or Visual Basic, JavaScript or C++), as the languages are very different both in terms of syntax and application design.

However, all is not lost if your iOS app relies on C++ code. As you know, iOS supports C++ development (you can compile C++ in Xcode alongside Objective-C). If you have been using C++, perhaps in a library or a framework, you can use this code very easily in your Windows app.

Here are some ways to re-use C++ code:

  • Create a C++ Windows Store project (or Windows Phone Store app, or Universal Windows app), and drop in your C++ source code. If your code follows a Model View Controller or MVVM pattern, and so the UI is handled separately, this approach can work well.
  • Create a project, and create a Windows Runtime Component to encapsulate the C++ in a DLL. The DLL can then be accessed by C#, Visual Basic, JavaScript or even C++ projects.

Using a Windows Runtime Component to access C++ code

A Windows Runtime Component is essentially a DLL (a Dynamic Link Library) which can be used by a Windows Store app written in any supported language. This is perfect if your app requires a standalone library of high-performance code, for example, image processing or physics modeling.

To create your component, you need to write some wrapper code to access the classes and manage passing the data in and out. For more info, see Creating Windows Runtime Components in C++. Remember, your app can be written in C#, Visual Basic, JavaScript or even C++, and it can still access the component.

Sharing other source code

If you are starting work on an iOS project rather than porting an existing one, there are several interesting options available to you that will make porting your app – or developing a Windows version in parallel – a lot more straightforward. For example, using a cross-platform tool such as Xamarin or MonoGame allows you to write a lot of your project directly in C#, making porting to Windows almost trivial.

Similarly, if you are developing an app in HTML5/JavaScript, either as a stand-alone project or using a third party tool such as PhoneGap, it will be quite easy to support Windows alongside any other platforms. Using an authoring tool such as Unity3D makes things even simpler, as you can deploy the project to any supported platform after it's completed.

Walkthrough: Creating a basic Windows Runtime component in C++ and calling it from JavaScript or C#

Code libraries, toolkits and other sources of help

Blog post on building your own Windows Runtime components for Windows Store apps

Creating Windows Runtime Components in C++

Port from OpenGL ES 2.0 to Direct3D 11

Guide to Porting an OpenGL ES 2.0 Application from iOS to Windows 8

ANGLE for Windows Store