简体   繁体   English

同时具有Objective-c和Swift的iOS应用-优点和缺点

[英]iOS app that has both Objective-c and Swift - pros & cons

I work with an App that's 100% Objective-C and I'd like to start transitioning over to include Swift. 我使用的是100%Objective-C的应用,我想开始过渡到包含Swift。 Due to the size of the codebase, it's unrealistic that I'll have a 100% Swift app anytime soon. 由于代码库的大小,我很快就会拥有100%Swift应用程序是不现实的。

As soon as a swift file is added, I noticed that the app size increases because now, the app needs to the include Swift run-time. 一旦添加了swift文件,我注意到应用程序的大小会增加,因为现在,该应用程序需要包含Swift运行时。

How else does things change? 事情还会如何变化? As soon as you include a Swift file, what is the process that the compiler and linker undergoes to ship a binary that is now multiple language & related frameworks? 包含Swift文件后,编译器和链接器交付二进制文件(现在是多种语言和相关框架)要经历的过程是什么?

Are there any other caveats in transitioning into a mixed language world in a somewhat large codebase? 在相当大的代码库中过渡到混合语言世界还有其他警告吗?

In my experience, it works surprisingly well. 以我的经验,它的效果令人惊讶。 It is advisable however, to wait to Xcode 7 / Swift 2.0 / Objective-C with generics support as that will eliminate a round of updates, allow you to interop from Objective-C with more elegant Swift code, and eliminate the Swift RT linking concern now that they have stabilized the runtime. 但是建议您等待Xcode 7 / Swift 2.0 / Objective-C的泛型支持,因为这将消除一轮更新,允许您使用更优雅的Swift代码从Objective-C互操作,并消除Swift RT链接问题现在他们已经稳定了运行时间。

Aside from that, both compilers need to run, Swift first, Objective-C second, the swiftc compiler can be pretty fast or really really slow, depending on what innocent and otherwise legal Swift code that you write (this is also true of a Swift-only app of course). 除此之外,两个编译器都需要运行,首先是Swift,然后是Objective-C,Swiftc编译器可以相当快或实际上真的很慢,这取决于您编写的是无辜的或其他合法的Swift代码(Swift也是如此) -当然是唯一的应用)。

Getting started, you need to read the interop guide, learn how the bridging header works, and are then mostly on your way. 入门之前,您需要阅读互操作指南,了解桥接头的工作方式,然后大部分就在您的路上。 I would say that having a mixed app is actually a blessing as you are not pressed to learn and do everything at once. 我想说,拥有混合应用程序实际上是一种祝福,因为您不会被迫同时学习和做所有事情。 Opinions will vary of course, but this is mine. 意见当然会有所不同,但这是我的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM