July 18th, 2013

Introduction to building Xamarin.iOS applications in Visual Studio

Jayme Singleton
Senior Program Manager C&AI

vs-with-ios

For many software developers on the Windows platform, Visual Studio is synonymous with C# programming. Developers who have spent much of their professional lives in Microsoft’s popular IDE can’t imagine using anything else. Fortunately, Xamarin makes it possible for these developers to reach every major mobile platform without having to leave the comfort of their favorite development environment.

Xamarin 2.0, released earlier this year, introduced support for building Xamarin.iOS applications in Visual Studio. Alongside Xamarin’s existing Android support, the Xamarin 2.0 release makes it possible for developers to use Visual Studio for projects that span iOS, Android, and Windows—all from one solution, coding in one programming language, with one IDE.

This blog post will give you a concise introduction to Xamarin.iOS development in Visual Studio—it will walk through some of the key features and give you an inside inside look at some of the best practices and recommended workflows.

Configuring Visual Studio for iOS development

Xamarin.iOS for Visual Studio makes it possible to develop iOS applications on Windows, but you will still need a Mac in order to compile and run the code. Xamarin’s Visual Studio extension communicates with your Mac over the local network, using it as a build server. Xamarin’s network build system is easy to configure and enable. The build service, which runs in the background on a Mac, comes bundled with the Xamarin installer for OS X.

vs-iosconnect

Before you start building your application, install Xamarin on both your PC and your Mac. Please note that you will also need a paid edition of Visual Studio—the free “Express” editions do not support installing Visual Studio extensions. After installation is complete, you will be able to select an iOS template in Visual Studio’s New Project dialog. When you create a new iOS project, Xamarin’s Visual Studio extension will help you find all available Mac build servers on the local network and allow you to select the one that you want to use.

If you want to get started quickly, try using the iPhone “Hello World” template. It includes a file with a sample view controller, which you will see in the Visual Studio solution pad. The sample view controller’s ViewDidLoad method creates a UIButton control, assigns a callback for the button push event, and adds the button to the view. Try modifying some of the code—you will see that Visual Studio intellisense works exactly as you would expect. Xamarin ensures that you get full support for code completion and method parameter hints across all of the iOS APIs.

vsselectiosproject

When you are ready to test your application, click the “Start” button in Visual Studio’s debugging toolbar. Xamarin’s Visual Studio extension will automatically send the project’s code over to the Mac for compilation. Any build errors that are encountered during the compilation process will be sent back and presented in Visual Studio.

During debugging, iOS applications execute within the iOS simulator on the Mac or on an actual iOS device. The headless debugging system in Xamarin.iOS relays information to Visual Studio over the network, providing the same kind of seamless experience that you would get if you were debugging an application on the local system. This enables you to take full advantage of Visual Studio’s built-in debugging tools: set breakpoints, walk through execution, create watch expressions, and browse local variables.

Getting the best experience

Today, Xamarin.iOS integration in Visual Studio is focused on enabling developers to develop in C#. Xamarin developers who write Xamarin.iOS applications on Windows typically hand-code their user interfaces—or they will need to switch to the Mac to use Xcode (or a beta version of Xamarin’s new iOS Designer) to interactively design an iOS user interface layout.

Coding a user interface entirely in C# is fairly straightforward, offering many advantages over designer-based user interface development. Xamarin.iOS for Visual Studio comes with several simplified iOS application templates that eschew XIB and Storyboard files, giving developers the option of building their entire user interface in code. Xamarin’s popular MonoTouch.Dialog library—which provides a simple, declarative API for building iOS user interface layouts in code—might prove especially useful to developers who want to define their user interfaces in code.

visualstudioios

For developers who would prefer to work with a graphical designer, the high degree of interoperability between Xamarin Studio and Visual Studio makes it easy to switch between the two environments when moving between a PC and Mac. A developer can do most of their work with Visual Studio on Windows and then jump over to Xamarin Studio on a Mac for building the user interface. The same exact project and solution files can be used in both environments.

Many Xamarin.iOS developers find that they are most productive when they use Windows and Mac OS X together. There are several different strategies that users can adopt to minimize the friction of switching between the two platforms. One of the most effective ways to do iOS development in Visual Studio is to run Windows in virtualized environment on a Mac.

Using virtualization gives the user the best of both worlds, allowing them to use the full functionality of the iOS SDK and the full power of Visual Studio on the same computer. A developer could similarly use a Mac and a PC side by side—either using a screen sharing technology like VNC or by having a separate monitor on each one and using something like Synergy to share the keyboard and mouse.

Conclusion

Xamarin aims to make Visual Studio a first-class citizen for iOS and Android development. The current generation of Xamarin’s Visual Studio extension is already fairly mature, offering a high level of iOS support and tight integration with useful features like the Xamarin Component Store. Future versions will be even more compelling, enabling an end-to-end iOS development workflow in Visual Studio when Xamarin’s new iOS designer arrives on Windows. To learn more about developing Xamarin.iOS applications in Visual Studio, you can refer to the useful guides provided by the Xamarin documentation team.

Author

Jayme Singleton
Senior Program Manager C&AI

Proud Business Operations Program Manager at Microsoft for the global Xamarin & .NET Developer communities. Apart from managing developer content, Jayme also collaborates with Microsoft PM teams, MVPs, Community Leaders, and Event Coordinators to organize product launches, MVP Summit, Microsoft /Build, .NET Conf, and other corporate events through the year. You can find her living the "City Life" in New York, or traveling around the world, Carmen Sandiego-style.