Mono + Xcode: How to author a library in C# using Xamarin Studio, and consume it in a CocoaTouch project within Xcode?

元气小坏坏 提交于 2019-12-11 12:07:31

问题


For an iOS app that will eventually be ported to Android/Winphone, I would love to be able to write some re-usable libraries in c#, but author the iOS UI in traditional Obj-C and reference the library written in c# from Xcode and consume it from Obj-C.

I've found lots of docs that talk about going the other way via bindings (Obj-C -> C#), but not much pertaining to my question. Also, a similar question was asked 4 years ago here, but a lot has changed in the ecosystem, the info seems out of date, and some of the links in the answers now redirect elsewhere:

  • Is there a way to mix MonoTouch and Objective-C?

So, is this possible? If so how, and what's the best way to achieve it today? (Or alternately, is this a bad idea and should be abandoned?)


回答1:


No, it is not currently possible to consume a C# library from Objective-C.

Note that it is usually possible to do it the other way with some ingenuity - the only real requirement is that the app must be a Xamarin.iOS app and the entry point the managed Main method. In your Main method you can call into native (C/Objective-C) code and have all your logic there.



来源:https://stackoverflow.com/questions/17995215/mono-xcode-how-to-author-a-library-in-c-sharp-using-xamarin-studio-and-consu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!