简体   繁体   English

iOS / XCode在目标中分离图层

[英]iOS / XCode separate layers in targets

I am fairly new to iOS and XCode and come from .Net background. 我是iOS和XCode的新手,并且来自.Net背景。 So in Visual Studio I would usually separate the layers of my application (say WebApp layer, business logic layer, data access layer etc.) into separate project so I can have control over what each project depends on etc. 因此,在Visual Studio中,我通常会将应用程序的各个层(例如WebApp层,业务逻辑层,数据访问层等)分离到单独的项目中,这样我就可以控制每个项目所依赖的对象等等。

So my question is if there is something similar in XCode? 所以我的问题是XCode中是否有类似的东西? I tried using the static library template for a target and it seems to be working but I am wondering if there are any drawbacks for this approach? 我尝试将静态库模板用于目标,但似乎可以正常工作,但是我想知道这种方法是否有缺点? All the examples I find on the Internet just show a folder structure in the app target for the layers is this the preferred way of doing it and why? 我在Internet上找到的所有示例仅显示了应用程序目标中各层的文件夹结构,这是这样做的首选方式,为什么?

I am also using Swift if that makes any difference but I still do have dependencies on 3rd party libraries developed in Objective-C 如果这有任何区别,我也使用Swift,但是我仍然对在Objective-C中开发的第三方库有依赖性

New in Xcode 6 / iOS 8, you can make a framework, thus dividing your code into multiple targets. Xcode 6 / iOS 8中的新增功能,您可以创建一个框架,从而将代码分成多个目标。 This is a nice easy way to separate reusable functionality. 这是分离可重用功能的简便方法。 It also has the advantage of privacy; 它还具有隐私的优势; in Swift, each framework is a module, and one module that imports another module can see only those members of the imported module that are declared public. 在Swift中,每个框架都是一个模块,导入另一个模块的一个模块只能看到已声明为public的导入模块的那些成员。

In general, however, I would suggest that you not worry about this; 但是,总的来说,我建议您不要为此担心。 just keep your classes organized conceptually using the MVC architecture that Cocoa encourages, and physically organize them within your project using "groups" (the fake folders that appear in Xcode's project navigator). 只需使用Cocoa鼓励的MVC架构在概念上组织类,并使用“组”(出现在Xcode项目导航器中的假文件夹)在项目内实际组织它们。 The reason is that very little of your code is going to prove to be reusable anyway, so it's really just a matter of making editing / developing / maintaining this project as easy as possible. 原因是您的代码很少会被证明可重用,因此实际上只是使编辑/开发/维护项目尽可能简单的问题。

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

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