WinObjC - Compiling Objective-C code with Visual Studio

When Microsoft announced that you can now compile iOS, Mac OSX and Android applications using Visual Studio, it got a lot of developers interested. After all, developers want to write a single code base want to release for as many platforms as one can. It is about maximizing the reach and maybe capturing a market that did not exist. Most importantly for clients, have an application that is usable for a majority of their clients that might have iPhones and a strange combination (and expectation) with Android Phones.

Project Islandwood

What is released on GitHub as WinObjC started off it's life as Project Islandwood, windows bridge for iOS. This allows the developer to compile Objective-C code within Visual Studio.

Issues

This is experimental (that's what Microsoft states) however, I believe they are using this code base for some of their own projects.There are a couple of requirements of being able to use WinObjC.

You will need to have Visual Studio 2015 and Visual C++ and Universal Windows App Development Tools. You can get the Visual Studio 2015 Community edition from here.

However the issues that you could face are with a previous installation of Visual Studio or the new install not completing or crashing mid-way. This can be a very frustrating up-hill journey. The other issue is when visual studio extensions fail to install half the tools and templates are unavailable.

More Issues

With the templates and tools not installing and Visual Studio not setting up properly, the chances of this working are limited. However, you need to install WinObjC SDK from GitHub and unzip this. It has a couple of directories as follows
bin -> Prebuilt tools
build -> Projects to build the SDK
deps -> Open source dependencies
prebuilt -> Prebuilt binaries for different architectures
frameworks -> Implementation of the iOS Style frameworks
include -> SDK Headers
platforms -> Headers for Windows Obj-C bindings
msvc -> Visual Studio integration
samples -> Sample code
tools -> Source code for the tools

If you want to run the sample code, it might not work at first run. However if you open and build the project from the build directory, then you would be able to run your sample code.

Sample Code

There are two samples available with the SDK, one is HelloUI that has a pulsating label and a button that you can move around.
The other is WOCCatalog which is the KitchenSink or the catalog of all the functionality available in this SDK. This is interesting if you want to check out all that is available. Though personally I am not a fan of the blue theme that is used.

On a personal note, chiming in with what folks have been commenting, where's Swift support. For Microsoft, Swift is so much closer to the new version of C# that it should be easy. In addition to that once Apple releases the open source version of Swift, Microsoft can leverage on that (hopefully). It is nice that Visual Studio will compile Android (Java) code and iOS (Objective-C) code but after having a taste of Swift, many are happier with Swift than Objective-C.

Compiling your own Xcode project

The one major contributing factor towards the success of an IDE or language is how easy is it to get started with. There are the masochist developers that believe that if a user cannot code and compile from the command-line then they aren't real programmers. Well, I subscribe to a different thought where I believe that the developer should focus on the code than the compiler settings etc. Like a Race car driver should focus more on their driving skills than on the mechanics of the car. There is a difference in knowing about the car vs being a mechanic than a race driver.

There is not much in terms of information regarding how to port your Xcode project to WinObjC, you can try to tinker, copy the files, but not achieve success on this path. However, strangely there is a file called samples.txt that contains the instructions of running vsimported.exe on the project to generate a .sln file which can then be used to compile and run your code.

However, I did not find a .sln file; instead I found a directory called .vsimporter that contained a .vcxproj file. I must confess that I fell off the Microsoft wagon when they took away VB6 (Visual Studio 6) and forced Visual Studio upo developers. Working with most IDE's specifically Xcode (and having written a book on that) it is one of the best IDE. It must definitely be me and I did not find an easy way to find procedures and functions in the class. It was available with VB6, it is available with most text editors but I could not find it easily with Visual Studio. Then on compiling the iOS app that was approximately 2MB with the graphics when compiled on the Mac was approximately 103MB (debug version) which is not very promising.

Proof of the pudding - The Eating

Upon running this executable, it immediately found an exception and crashed, rather hung (partially also because Windows 10 was updating automatically without providing an option. Back to the point, the use CoreGraphics, QuartzCore on windows is quite impressive. Hopefully with the next release (update) of Visual Studio this might be integrated than an external project. Till then Project Islandwood is just an exciting project with possibilities.

All IDE's get additional features, XCode which used to be a series of utilities are all confined into one IDE and with each iteration it has had new and improved features. With Visual Studio (partially because I do not use it as much) I feel that there hs been not much of a change and in fact it is less user friendly. Cannot recall who but there was someone (at Microsoft) that had commented that "We are building the best IDE based on feedback from our developer community". Like many other (I hope other developers have a similar thought) I would like to have a single IDE and single language. Multiple languages and IDE's are quite distracting and counter productive. To be honest and in all fairness Microsoft are doing it right, however when it is not usable, it feels like something that has wasted your time. That was surprisingly the feeling I had when I got my first MacBook, with a Windows Box/Laptop I had a CD full of utilities to install and work with. It has come full circle and never thought I would say that, today I find more value and options with a Mac than with Windows. I was hoping Visual Studio to change that, but maybe VS 2016 might.

Universal Applications

When WinObjC did not work well for my project, I tried to build the Javascript Universal project to embed a website, in my case it was my website which is found at www.oz-apps.com. It did not work for me either because Visual Studio does not work for me :( or that it expects the site to be created with certain Microsoft technologies to be integrated (which I thought should not be the case). It would be easier and faster to build the same using old technology like VB6 and a WebBrowser component. A bit of a let down specially when majority of the enterprise software runs on Windows technologies generally Visual Studio products (VB6, DotNet, C#, VB.Net, ASP.Net, Visual FoxPro, etc)

UPDATE

It was less than 24 hours of WinObjC being released, that it caused a whole lot of activity around it on the interwebs. To start with, the contributors of the Cocotron library that is the basis for many of the classes present in WinObjC did not appreciate their names and licenses being removed. The Cocoatron project can be found here. The instructions are quite detailed and work with Xcode, so that for me is a win, I can continue to use my Mac but compile for Windows or Linux too.

One small issue (which will be part of another article) is the cost of using Open Source Code in your projects. From a personal experience, HipTic Games; The developers of GoNinja used a component that I had created and they reference that in the credits. Though it makes me no money, it at least looks good in terms of recognition. I had to remove that component because there were some other developers that did not quite embrace the idea. So I am apprehensive about posting code (not that I write some of the most amazing code that everyone is queuing up to download) still, if you would want, you can have a look at my GitHub repository at https://github.com/JayantVarma where currently the code from my Objective-C and Swift book are available.

HOWEVER... the Open Source is really bugging especially when it does not work. Admitted that the road to being Midas is difficult. Till then the options like Xojo (RealBasic), QT, etc are still more stable and viable for multi-platform development. It would have been such fun if it worked. Well, wasted time ... back to what works.

libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I/Developer/Cocotron/1.0/Source/binutils-2.21-20111025/bfd -I. -I/Developer/Cocotron/1.0/Source/binutils-2.21-20111025/bfd -I/Developer/Cocotron/1.0/Source/binutils-2.21-20111025/bfd/../include -DHAVE_i386pe_vec -DHAVE_i386pei_vec -DHAVE_bfd_elf32_i386_vec -DHAVE_bfd_elf32_little_generic_vec -DHAVE_bfd_elf32_big_generic_vec -I./../intl -DBINDIR=\"/Developer/Cocotron/1.0/Windows/i386/gcc-4.3.1/bin\" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -m32 -Wformat=0 -Wno-error=deprecated-declarations -MT elf32-i386.lo -MD -MP -MF .deps/elf32-i386.Tpo -c /Developer/Cocotron/1.0/Source/binutils-2.21-20111025/bfd/elf32-i386.c -o elf32-i386.o
/Developer/Cocotron/1.0/Source/binutils-2.21-20111025/bfd/elf32-i386.c:326:15: error: array index 42 is past the end of the array (which contains 34 elements)
      [-Werror,-Warray-bounds]
      return &elf_howto_table[R_386_IRELATIVE];
              ^               ~~~~~~~~~~~~~~~
/Developer/Cocotron/1.0/Source/binutils-2.21-20111025/bfd/elf32-i386.c:37:1: note: array 'elf_howto_table' declared here
static reloc_howto_type elf_howto_table[]=
^
1 error generated.
make[4]: *** [elf32-i386.lo] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-bfd] Error 2
make: *** [all] Error 2

Why would a developer want to attempt to fix that issue and spend time on something that MIGHT not work.

Comments

Popular Posts