在今天的一个本地。net活动上,Mono的使用被“提及”为iPhone开发的替代方案。在c#和。net中非常舒适,这似乎是一个有吸引力的选择,尽管Mono堆栈有一些奇怪的地方。然而,由于MonoTouch的售价为400美元,我有些纠结于这是否是iPhone开发的发展方向。
有人用MonoTouch和Objective-C开发过吗?如果是的话,用MonoTouch开发比学习Objective-C更简单、更快,而且值得花400美元吗?
在今天的一个本地。net活动上,Mono的使用被“提及”为iPhone开发的替代方案。在c#和。net中非常舒适,这似乎是一个有吸引力的选择,尽管Mono堆栈有一些奇怪的地方。然而,由于MonoTouch的售价为400美元,我有些纠结于这是否是iPhone开发的发展方向。
有人用MonoTouch和Objective-C开发过吗?如果是的话,用MonoTouch开发比学习Objective-C更简单、更快,而且值得花400美元吗?
当前回答
所以,我对之前类似问题的回答是学习Objective-C。(另外,不要忘记调试支持)
This will probably offend some but to be honest, if you are going to do any serious development, you should learn Objective-C. Not knowing Objective-C in iPhone development will just be a hindrance. You won't be able to understand many examples; you have to deal with the quirks of Mono whereas if you had a working knowledge of Objective-C you could get a lot more out of the platform documentation. Personally, I don't understand the position that says increasing the amount of information you need in favor of using Mono over the platform's native language. It seems somewhat counterproductive to me. I think if this is a very expensive proposition (learning a new language) then it may be worthwhile spending some time on fundamental programming concepts so that learning new languages is a fairly cheap proposition.
另一位用户也这样写道:
现在单触摸对你来说更容易了。但之后就更难了。
例如,当新的种子出现时,你需要测试,但由于某种原因破坏了MonoTouch,会发生什么?
通过坚持使用Mono,任何时候你在寻找框架的资源时,你都必须在心里转换成你将如何在Mono中使用它们。你的应用二进制文件会更大,在使用Objective-C几个月后,你的开发时间不会更快,而其他应用开发者会比你更有优势,因为他们使用的是原生平台。
另一个需要考虑的问题是,您希望使用c#,因为您对该语言比Objective-C更熟悉。但是iPhone学习曲线的绝大部分并不是Objective-C,而是框架——你也必须调用c#。
对于任何平台,你都应该使用直接表达该平台设计理念的平台——在iPhone上,那就是Objective-C。从相反的角度考虑这个问题,如果一个习惯用GTK编程的Linux开发人员想要编写Windows应用程序,你会认真地建议他们不要使用c#而坚持使用GTK,因为这样做对他们来说“更容易”吗?
其他回答
我个人认为你只学习Objective-C会过得更好。
简而言之:
“学习Objective-C”并不像你想象的那样令人生畏,你甚至会在最初几周后就喜欢上它 你已经熟悉了含有大量*&(){}的“C风格”语法;到处都是 苹果在记录方面做得很好 你将以苹果公司预期的方式与iPhone互动,这意味着你将直接从源头获得好处,而不是通过某种过滤。
我发现像Unity和MonoTouch这样的项目应该“节省你的时间”,但最终你还是需要学习他们的领域特定语言,有时不得不回避一些事情。所有这些可能会花费你学习你试图避免学习的语言的时间(按日历时间计算)。最后你并没有节省任何时间,而是与某些产品紧密耦合。
编辑:我从未想过要暗示任何关于。net的负面信息,我只是碰巧是它的忠实粉丝。我的观点是,仅仅因为你还不习惯古怪的objc括号符号,就添加更多的复杂性层,对我来说真的没有多大意义。
2019年更新:7年过去了。我现在仍然有同样的感觉。当然,使用“领域特定语言”可能是错误的,但我仍然相信,最好直接为您正在使用的平台编写,并尽可能避免兼容层和抽象。如果你担心代码重用和重做,一般来说,你的跨平台应用需要执行的任何功能都可以通过现代web技术来完成。
补充一下其他人已经说过的话(好吧!):我的感觉是你基本上把你需要担心的bug数量增加了一倍,把MonoTouch中的bug添加到iPhone OS中已经存在的bug中。更新新的操作系统版本将比正常情况下更加痛苦。恶心,到处都是。
我认为MonoTouch唯一引人注目的情况是,那些有大量c#程序员和c#代码的组织必须在iPhone上使用。(就是那种3500美元都不眨眼的商店。)
但对于任何从零开始的人来说,我真的不认为这是值得或明智的。
我会花时间在Objective-C上,主要是因为你可以从这样的网站上得到帮助。Objective-C的优点之一是你可以使用C和c++代码,而且有很多项目都经过了很好的测试。
另一件事是你的代码(语言选择)将被苹果支持。什么是ios5。例如,x删除了对第三方解决方案如MonoTouch?你会怎么告诉你的客户?
如果你还没有完全准备好转向Objective-C,也许使用HTML5等独立于平台的解决方案会更好?
作为一个同时拥有c#和Objective-C经验的人,我想说对于大多数人来说Xamarin是物有所值的。
c#是一门设计得很好的语言,c# API也是设计得很好的。当然Cocoa Touch的API(包括UIKit)也有很好的设计,但是语言可以在几个方面得到改进。当你用c#写代码时,你可能会比用Objective-C写相同的代码更有效率。这是由于几个原因,但其中一些原因是:
C# has type inference. Type inference makes writing code quicker, since you don't have to "know" the type on the left-hand side of an assignment. It also makes refactoring easier and more saver. C# has generics, which will reduce errors compared to equivalent Objective-C code (though there are some work-arounds in Objective-C, in most situations developers will avoid them). Recently Xamarin added support for Async / Await, which makes writing asynchronous code very easy. You'll be able to reuse part of the code base on iOS, Android and Windows Phone. MonoTouch largely implements the CocoaTouch API's in a very straightforward way. E.g.: if you've got experience with CocoaTouch, you'll know where to find classes for controls in MonoTouch (MonoTouch.UIKit contains classes for UIButton, UIView, UINavigationController, etc..., likewise MonoTouch.Foundation got classes for NSString, NSData, etc...). Xamarin will give users a native experience, unlike solutions like PhoneGap or Titanium.
现在Objective-C比c#有一些优势,但在大多数情况下,用c#编写应用程序通常会减少开发时间和更清晰的代码,并减少将同一应用程序移植到其他平台的工作。一个值得注意的例外可能是依赖OpenGL的高性能游戏。
我最近经常看到这个问题(以及它的变体)。让我惊讶的是,人们经常回复,但很少有人回答。
我有我的偏好(我喜欢这两组),但这是大多数“答案”开始出错的地方。它不应该是关于我想要什么(或其他人想要什么)。
以下是我如何决定MonoTouch的价值-我不能客观,显然,但我认为这是相当狂热的:
Is this for fun or business? If you wanted to get into consulting in this area, you could make your $399 back very quickly. Do you want to learn the platform inside-out, or do you "just" want to write apps for it? Do you like .Net enough that using a different dev stack would take the fun out of it for you? Again, I like both stacks (Apple and Mono), but for me MonoTouch makes the experience that much more fun. I haven't stopped using Apple's tools, but that's mainly because I really do enjoy both stacks. I love the iPhone, and I love .Net. In that case, for me, MonoTouch was a no-brainer. Do you feel comfortable working with C? I don't mean Objective-C, but C - it matters because Objective-C is C. It's a nice, fancy, friendly OO version, but if pointers give you the heebie-jeebies, MonoTouch is your friend. And don't listen to the naysayers who think you're a dev wuss if it happens that you don't like pointers (or C, etc.). I used to walk around with a copy of the IBM ROM BIOS Pocket Reference, and when I was writing assembly and forcing my computer into funny video modes and writing my own font rendering bits for them and (admittedly trashy) windowing systems, I didn't think the QuickBasic devs were wusses. I was a QuickBasic dev (in addition to the rest). Never give in to nerd machismo. If you don't like C, and if you don't like pointers, and if you want to stay as far away from manual memory management as possible (and, to be fair, it's not bad at all in ObjC), then... MonoTouch. And don't take any guff for it. Would you like to target users or businesses? It doesn't matter much to me, but there are still people out there on Edge, and the fact is: you can create a far smaller download package if you use Apple's stack. I've been playing around with MonoTouch, and I have a decent little app going that, once compressed, gets down to about 2.7 MB (when submitting your app for distribution, you zip it - when apps are downloaded from the store, they're zipped - so when figuring out if your app is going to come in under the 10MB OTA limit, zip the sucker first - you WILL be pleasantly surprised with MonoTouch). But, MT happiness aside, half a meg vs. nearly three (for example) is something that might be important to you if you're targeting end users. If you're thinking of enterprise work, a few MB won't matter at all. And, just to be clear - I'm going to be submitting a MT-based app to the store soonishly, and I have no problem whatsoever with the size. Doesn't bother me at all. But if that's something that would concern you, then Apple's stack wins this one. Doing any XML work? MonoTouch. Period. String manipulation? Date manipulation? A million other little things we've gotten used to with .Net's everything-AND-the-kitchen-sink frameworks? MonoTouch. Web services? MonoTouch. Syntactically, they both have their advantages. Objective-C tends to be more verbose where you have to write it. You'll find yourself writing code with C# you wouldn't have to write with ObjC, but it goes both ways. This particular topic could fill a book. I prefer C# syntax, but after getting over my initial this-is-otherworldly reaction to Objective-C, I've learned to enjoy it quite a bit. I make fun of it a bit in talks (it is weird for devs who're used to C#/Java/etc.), but the truth is that I have an Objective-C shaped spot in my heart that makes me happy. Do you plan to use Interface Builder? Because, even in this early version, I find myself doing far less work to build my UIs with IB and then using them in code. It feels like entire steps are missing from the Objective-C/IB way of doing things, and I'm pretty sure it's because entire steps are missing from the Objective-C/IB way of doing things. So far, and I don't think I've sufficiently tested, but so far, MonoTouch is the winner here for how much less work you have to do. Do you think it's fun to learn new languages and platforms? If so, the iPhone has a lot to offer, and Apple's stack will likely get you out of your comfort-zone - which, for some devs, is fun (Hi - I'm one of those devs - I joke about it and give Apple a hard time, but I've had a lot of fun learning iPhone development through Apple's tools).
要考虑的事情太多了。价值是如此抽象。如果我们谈论的是成本和是否值得,答案就归结为我的第一个项目:如果这是为了生意,如果你能得到这份工作,你就能赚回你的钱。
所以…这是我最客观的评价了。这是一个你可能会问自己的问题的简短清单,但这只是一个起点。
就我个人而言(让我们暂时放弃客观性),我喜欢并使用这两种方法。我很高兴我先学会了苹果堆栈。当我已经熟悉苹果的世界时,使用MonoTouch会更容易上手。正如其他人所说,你仍然要使用CocoaTouch——它只是将在一个。net化的环境中。
但不止于此。没有使用过MonoTouch的人往往会止步于此——“这是一个包装器等等”——这不是MonoTouch。
MonoTouch让你访问CocoaTouch所提供的功能,同时也让你访问。net所提供的(一个子集),一个一些人觉得更舒服的IDE(我是其中之一),更好地与Interface Builder集成,尽管你不能完全忘记内存管理,但你得到了一个很好的余地。
如果你不确定,抓取苹果的堆栈(它是免费的),抓取MonoTouch的eval堆栈(它是免费的)。在你加入苹果的开发程序之前,这两种软件都只能在模拟器上运行,但这足以帮助你弄清楚你是否更喜欢其中一种,以及MonoTouch对你来说是否值得花399美元。
不要听那些狂热者的话——他们往往是那些没有使用过他们所指责的技术的人:)