您如何构建 iPhone Xcode 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3983144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do You structure an iPhone Xcode project?
提问by Scott McKenzie
What are good ways of building groups/folders?
建立组/文件夹的好方法是什么?
I've tried by feature (UI for a feature plus model etc) with a common group. I've also tried by UI, model, etc.
我已经尝试通过功能(功能加模型的用户界面等)与一个公共组。我也尝试过 UI、模型等。
The former keeps like things together which fits the iPhone paradigm nicely. The latter means I jump around a bit more.
前者将类似的东西放在一起,非常适合 iPhone 范式。后者意味着我跳得更多一点。
What do you think?
你怎么认为?
回答by A.G
The standard Xcode MVC folder structure is as follows.
标准的 Xcode MVC 文件夹结构如下。
CoreData: Contains DataModel and Entity Classes.
Extension: Contain One class(default apple class extensions+project class extensions.)
Helper: Contain Third Party classes/Frameworks (eg. SWRevealController) + Bridging classes (eg. Obj C class in Swift based project)
Model: Make a singleton class (eg.AppModel - NSArray,NSDictionary, String etc.) for saving data. The Web Service Response parsing and storing data is also done here.
Services: Contain Web Service processes (eg. Login Verification, HTTP Request/Response)
View: Contain storyboard, LaunchScreen.XIB and View Classes. Make a sub folder Cells - contain UITableViewCell, UICollectionViewCell etc.
Controller: Contain Logic or Code related to UIElements (eg. UIButton's reference+ clicked action)
CoreData:包含数据模型和实体类。
扩展:包含一个类(默认苹果类扩展+项目类扩展。)
助手:包含第三方类/框架(例如 SWRevealController)+ 桥接类(例如基于 Swift 的项目中的 Obj C 类)
模型:制作一个单例类(例如 AppModel - NSArray、NSDictionary、String 等)来保存数据。Web Service Response 解析和存储数据也在这里完成。
服务:包含 Web 服务进程(例如登录验证、HTTP 请求/响应)
View:包含 storyboard、LaunchScreen.XIB 和 View 类。创建一个子文件夹 Cells - 包含 UITableViewCell、UICollectionViewCell 等。
控制器:包含与 UIElements 相关的逻辑或代码(例如 UIButton 的引用+点击动作)
回答by Julian B.
Although John has a point, I actually created a project to demonstrate what I consider my general go-to Xcode project structure for a small or mid-sized code base. You can find it here.
尽管 John 有一个观点,但我实际上创建了一个项目来演示我认为我的中小型代码库的通用 Xcode 项目结构。你可以在这里找到它。
Here's an outline of it:
这是它的概述:
- Source - All source code
- Account - Account-related classes (session-related classes, account logic, etc)
- Application - Application-related classes. App delegate, configuration classes, etc
- Core Additions - Extensions and subclasses stemming from apple's classes
- Utilities - General utility classes. Useful extensions, formatting utilities, convenience classes and such
- Element-based folders - Folder for UIView, UITableViewCell, etc
- Local Persistence - Local persistence layer. All interactions with local database (realm, core data)
- Repositories - All model-related local persistence logic
- Constants - All constants. URLs, fonts, colors, errors, etc
- Models - All models (server-side entities' representation). We would also throw here any object mapping logic
- Modules - Here we can find each of the application's pieces divided by functionality
- Module-based folders - Each folder contains all module-specific view controllers, views, delegates and related classes
- Networking - The app's networking layer (e.g. classes responsible for interacting with web services)
- Services - All model-related web logic
- Storyboards - Contains all storyboard files
- Resources - Any additionaly resources like media, documents, localization files and such
- 源 - 所有源代码
- 帐户 - 帐户相关类(会话相关类、帐户逻辑等)
- 应用程序 - 与应用程序相关的类。应用委托、配置类等
- 核心添加 - 源自苹果类的扩展和子类
- 实用程序 - 通用实用程序类。有用的扩展、格式化实用程序、便利类等
- 基于元素的文件夹 - UIView、UITableViewCell 等的文件夹
- 本地持久性 - 本地持久层。与本地数据库(领域、核心数据)的所有交互
- Repositories - 所有与模型相关的本地持久化逻辑
- 常量 - 所有常量。URL、字体、颜色、错误等
- 模型 - 所有模型(服务器端实体的表示)。我们还会在这里抛出任何对象映射逻辑
- 模块 - 在这里我们可以找到按功能划分的应用程序的每个部分
- 基于模块的文件夹 - 每个文件夹包含所有特定于模块的视图控制器、视图、委托和相关类
- 网络 - 应用程序的网络层(例如负责与网络服务交互的类)
- 服务 - 所有与模型相关的网络逻辑
- 故事板 - 包含所有故事板文件
- 资源 - 任何其他资源,如媒体、文档、本地化文件等
回答by John Smith
It's going to be very project dependent. In my last project I had mostly views, and so I organized the views by view-type.
这将非常依赖项目。在我的上一个项目中,我主要有视图,因此我按视图类型组织了视图。