问题
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.
The former keeps like things together which fits the iPhone paradigm nicely. The latter means I jump around a bit more.
What do you think?
回答1:
The standard Xcode MVC folder structure is as follows.
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)
回答2:
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.
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
回答3:
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.
来源:https://stackoverflow.com/questions/3983144/how-do-you-structure-an-iphone-xcode-project