How do You structure an iPhone Xcode project?

青春壹個敷衍的年華 提交于 2019-12-03 00:53:39

问题


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.

  1. CoreData : Contains DataModel and Entity Classes.

  2. Extension : Contain One class(default apple class extensions+project class extensions.)

  3. Helper: Contain Third Party classes/Frameworks (eg. SWRevealController) + Bridging classes (eg. Obj C class in Swift based project)

  4. 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.

  5. Services : Contain Web Service processes (eg. Login Verification, HTTP Request/Response)

  6. View : Contain storyboard, LaunchScreen.XIB and View Classes. Make a sub folder Cells - contain UITableViewCell, UICollectionViewCell etc.

  7. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!