Xamarin deletes code from xcode RRS feed

  • Question

  • User186430 posted


    when i create a cocoa class (h and m file) which overrides NSButton, add some code and switch back to Xamarin, all my added code will be deleted. This happens to me all the time. Is this a bug or do i do something wrong?

    Saturday, January 9, 2016 9:50 PM

All replies

  • User95038 posted

    I think the entire projected is auto generated by Xamarin. It is only the C# solution and corresponding files that are checked in to git. Even if you remove the project (located under /obj/xcode/) then the project is recreated next time you try to edit your xib file using xcode.

    Sunday, January 10, 2016 2:41 PM
  • User142072 posted

    Yes i think. So what should i do so that i am able to write Code in XCode?

    Sunday, January 10, 2016 7:47 PM
  • User95038 posted

    I don't think this is possible. And if you are using Xamarin, you are developing your app in C#. Is there any particular reason why you want to write part of it in Swift (or Obj-C) ?.

    Monday, January 11, 2016 2:41 AM
  • User142072 posted

    Well if I want to make some UI things, like creating a custom toolbar, it is better to make it directly in Xcode and using existing code, than translating it to c#. So yes, there are many reasons

    Monday, January 11, 2016 7:35 AM
  • User95038 posted

    So yes, there are many reasons You might be right. However, then entire Cocoa API should be available in C#, meaning what you can do in Swift, you can do in C#, but in reality this might not be true. I'm still trying to learn the Cocoa API.

    Monday, January 11, 2016 2:26 PM
  • User35201 posted

    As mentioned by others, when you open up a xib / storyboard from Xamarin Studio, we create a temporary project to track changes you make to outlets / actions so we can generate the correct code to reference them. You can't just add objective-c code there.

    It is possible for sure to use managed and native code, you'll just have to do some legwork to set things up. You'll need to create a separate project or Makefile for the native code, build it, then generate code to invoke it from C#.

    A quick example on how to do this (for calling objective-c) is here: https://developer.xamarin.com/samples/mac/XMBindingExample/

    We're actively working on making this process significantly easier, but it is very possible right now.

    Oh, and if you want to call plain C code, that is even easier. P/Invokes (https://en.wikipedia.org/wiki/PlatformInvocationServices) work just fine. You just need to make sure your library is in the correct location in the bundle.

    Monday, January 11, 2016 2:28 PM
  • User35201 posted

    And to answer the last comment, unlike iOS, we do not guarantee 100% API coverage for Xamarin.Mac (there are a TON of APIs on Cocoa).

    We do however, have a huge chunk of the ones that a most commonly used, that is enough for most people.

    If you happen to hit ones we don't have coverage for, feel free to post here to see if anyone has a work around and/or follow the steps documented here (http://developer.xamarin.com/guides/mac/advanced_topics/binding-troubleshooting/).

    Monday, January 11, 2016 2:32 PM