简体   繁体   English

更多文件会增加Swift的编译时间吗?

[英]Do more files increase compile time in Swift?

I am currently using CLEAN Swift iOS architecture for a fairly large iOS app ( http://clean-swift.com ), it's based on Uncle Bob's Clean Architecture. 我目前正在将CLEAN Swift iOS体系结构用于一个相当大的iOS应用程序( http://clean-swift.com ),它基于Bob叔叔的Clean Architecture。 It really does reduce the size of the view controllers however there are a LOT of files for each scene (or screen). 它确实确实减小了视图控制器的大小,但是每个场景(或屏幕)都有很多文件。 A typical screen will have files such as: ViewController, Presenter, Interactor, Router, Configurator. 典型的屏幕将包含以下文件:ViewController,Presenter,Interactor,Router,Configurator。 We are also using a separate storyboard per view controller - each storyboard only has one view controller. 我们还在每个视图控制器上使用单独的情节提要-每个情节提要仅具有一个视图控制器。 There are also many worker files that do various api calls. 还有许多工作程序文件可以执行各种api调用。 The Swift compile time is fairly slow, but in my memory I'm pretty sure it always was (even before we changed our architecture from MVC to CLEAN). Swift的编译时间相当慢,但是在我的记忆中,我可以肯定它一直都是(甚至在我们将体系结构从MVC更改为CLEAN之前)。 However some coworkers are starting to question if this architecture is what is causing the slow compile times. 但是,一些同事开始质疑这种体系结构是否导致缓慢的编译时间。 My question is, does using more files increase the compile time? 我的问题是,使用更多文件会增加编译时间吗? Would MVC compile quicker? MVC编译会更快吗? Also, what about storyboards? 另外,情节提要怎么样? Is this bad practice using one per view controller? 每个视图控制器都使用一种不好的做法吗?

The short answer is yes. 简短的答案是肯定的。 More files increase compile time, some more than others. 更多的文件会增加编译时间,而其他文件则更多。
A way to reduce the compile time, is to remove storyboards and then do the ui in code, or make your storyboards as reusable as possible. 减少编译时间的一种方法是,删除情节提要,然后在代码中执行ui,或使情节提要尽可能可重用。 In my experience, clean architecture works best with an all-code, code base, as you reduce the number of view files, if done correctly. 以我的经验,如果正确完成的话,干净的体系结构最适合使用全代码的代码库,因为这样可以减少视图文件的数量。 Although another question you should ask yourself, is the slightly increased compile time, more beneficial in terms of having more readable, maintainable, and testable code, rather than messing with the ever increasing controllers of the MVC? 尽管您应该问自己另一个问题,是编译时间略有增加,在拥有更具可读性,可维护性和可测试性的代码方面,而不是与不断增加的MVC控制器相处时,是否更有益? And MVC might not even decrease your compile time, as you might end up having larger storyboards (in most cases). 而且MVC甚至可能不会减少编译时间,因为您最终可能拥有更大的故事板(在大多数情况下)。 And for the last question. 最后一个问题。 Yes one storyboard per controller could be considered bad practice, but only if these storyboards aren't reusable. 是的,每个控制器只有一个情节提要被认为是不好的做法,但前提是这些情节提要不可重复使用。

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

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