Forum General

Is there any way to "port" an iOS App to C# (Xamarin)?

DinisVieiraDinisVieira PTMember ✭✭
edited July 2014 in General


We currently have a big iOS (and Android) Application that is still going to get a lot more features. We also wanted to start building the Windows 8 App and it would be great to have a single code-base for all three using Xamarin.

Unfortunately, completely rewriting the entire Android and iOS Applications in C#/Xamarin is not an option.

Is there any way to port the iOS App to Xamarin? (the question also applies to Android, but I'm guessing iOS is the biggest problem)

Some ideas I had/tried:

  • Some way of translating Objective-C to C# (I'm guessing it would be worst than doing it from scratch). I tried Auto-Magical, but it didn't seem that effective because of the various Xamarin specific API and also because it doesn't handle Objective-C completely.
  • Can I in some way bind all the existing iOS Views (and Objective-C View-Controllers) and keep developing those views/controllers in native obj-c / xcode while sharing only the App Logic with the other apps in C#? I'm guessing not, because it's not possible to simply call C# stuff from the Obj-C ViewControllers, right?

Any other suggestions?

Dinis Vieira

Best Answers


  • softlionsoftlion FRBeta ✭✭✭

    First, you want to share only business code or also viewmodels ? You may want to use Xamarin.Forms (shared UI) or Mvvmcross (Shared viewmodels).

    You will be able to quite easily reuse Activities and ViewControllers in C#. 99.99% of what is doable in objectiveC is doable in C#.

    In my experience, don't go the binding way. It's just ... loosing time.

  • DinisVieiraDinisVieira PTMember ✭✭

    Just sharing the business code would be already great, but I haven't found any way to do it either.
    It would be great if I could build some sort of static library with Xamarin that could be used in native iOS/Android (XCode and Eclipse).
    But I guess it's asking too much :)

    When you talk about reusing Activities and ViewControllers do you mean the ones I built with Xamarin, or native Obj-C and Java?

    Reminder: I'm not starting from scratch, I already have a HUGE iOS/Android app (both built the native way) :)


  • PeterDavisPeterDavis USMember ✭✭✭
    edited July 2014

    @DinisVieira‌ There's no way really, to auto-convert your existing app to xamarin. To take advantage of Xamarin, you'd need to rewrite from scratch.

    Depending on how you coded it, you might be able to reuse some of your UI code.

    Now, that said, your best bet would probably be to convert your Android app. Converting Java to C# is pretty straight-forward. I have converted a ton of Java to C#. The languages are very similar, so the conversion is very straight-forward. There are also tools that can help with this:

    If you convert all your Java logic into a C# PCL (Portable Class Library), you can then share that logic between all 3 versions of your app. You would then need to port your UI.

    You can import your Android layout xmls directly into your app, so you won't have to mess with that. I believe you can bring over your iOS forms as well (I don't do iOS myself, so I'm not familiar with that part much).

    You say you can't rewrite from scratch, but if you're going to do a Windows Phone version, a rewrite is inevitable, since you can't convert from iPhone or Android to Windows Phone. But I think if you approach it by using your Android Java as the source, you'll find most of the conversion to be pretty straight-forward.

    You'd need to rewrite the view code behind your UIs, but if your controller logic is similar between the current Android and iOS versions, then it ought not be too tough to do this either, as you'd probably be able to convert it from your existing Android code.

  • DinisVieiraDinisVieira PTMember ✭✭

    Thanks @PeterDavis‌, that's also a good suggestion.
    Currently I'm trying another approach that might actually work. The current application is actually quite organized and already separated some libraries.
    So, we are going to try to handle the whole application (except the "business code" and landing/login view) as a big library to which we interact with Bindings. (mostly the contract between the C# and Obj-C side would have only to exchange models which are currently well defined in the app.
    Let's see if this works... :)

  • DinisVieiraDinisVieira PTMember ✭✭

    We are hoping that the bindings won't have to change that much with every features that we had. The models are actually pretty generic, so it should help :)

    I don't want to reuse this "iOS Library" in Windows 8, because it will contain mostly Views and View Controllers. We just want to reuse the "business code" that hopefully can be built in C# and be used by the "iOS/Android Libraries".

    It's ambitious, but we are giving it a try... :)

  • PeterDavisPeterDavis USMember ✭✭✭

    Ah, I see. Okay, good. I think that's a good plan. I think that'll work.

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    The big problem in going between Java and C# is that Java has a number of features within it that aren't there in C# - Anonymous methods being one of them

    Huh? C# has had anonymous methods since 2.0.

    If you meant anonymous classes, then yes.

  • nodoidnodoid GBMember, Beta ✭✭✭

    @DaveHunt‌ - sorry, yeah. 4.50am and brain not fully functioning :)

  • PeterDavisPeterDavis USMember ✭✭✭

    @nonoid, while this may be true, one can easily perform the work of an anonymous class in C# without an anonymous class. The differences between Java and C# are so few and of such minor degrees that the conversions are generally very straight-forward. I've rarely been stumped beyond a quick Google search and my experience with Java overall has been pretty minimal (I've written a few small native Android apps and that's about all the Java experience I've had.)

  • DinisVieiraDinisVieira PTMember ✭✭

    Thanks for all the suggestions guys, I'm still trying the Binding I told about earlier.
    And I almost did it, I'm just getting stuck in (I hope) a small Binding issue...

    I asked about it here:

  • JamalZafer.1538JamalZafer.1538 USUniversity ✭✭

    @DinisVieira : How was your experience implementing Xamarin solution?

Sign In or Register to comment.