I am not saying the following guidelines are perfect but I like to use them to bring consistency to my projects. I thought I would share in case someone else needs a place to get started.
- Use Pascal Case for files, folders and classes
- start with a capital letter
- i.e. Controllers, MyClass, BlueprintListTableViewController, etc.
- Use Camelcase for methods, functions, properties & variables
- start with a lowercase letter
- i.e createFirstName:, userPassword, etc.
- Avoid using acronyms and abbreviations
- do not create things like: usrPswdLbl
- just because Swift is a less verbose language than ObjeciveC does not mean I choose brevity over clarity when naming things
At the creation of this document Swift 2.0 is still in beta and evolving. There are no specific coding conventions that are considered the definitive guide. Until such a time we should follow the One True Brace Style (1TBS) and The Swift Programming Language book by Apple.
For Objective C guidelines the Apple Coding Guidelines for Cocoa should be followed.
iOS App xCode Project and Folder Structure
- Put things in the right place
- Map all Xcode group folder to the system directory
- Xcode groups don’t represent physical folder
- Review this stack overflow answer for the easiest way to create folders and groups.
- Remove “Supporting Files” group folder
- Supporting Files is too vague and can sometimes be a catch-all
Here is an example of the folder / group layout to use for projects. See the details below for more on the purpose of each.
Application – specific app related stuff like AppDelegate, main.m, .pch etc
Controllers – view controller and the components that make them
- Put .swift, .xib, .h, and .m together in the same folders
- One (physical) folder for each view controller
- If there are too many, group them into a subfolder
- Group them by tab (TabBar) or by functions
Libraries – specific application classes like helpers, base classes, services, etc
Models – application domain models and entities, Core Data model too
Resources – assets like images, fonts, sounds, videos, etc.
- .xcassets files should be used for all local images
- One folder for each type of asset (new images.xcassets are actually examples of this and can live at the top level of the Resources folder)
- images, fonts, sounds, videos, strings, plist
- If the app will support multiple themes, create a hierarchy
- themes > themes name > images, fonts, etc.
- Name image based on state
- ie: button_blue_norma, button_blue_highlighted
Vendors – third party libraries and frameworks
- Vendor SDKs and Libraries that are not supported by cocoapods
- These don’t belong in the Libraries Folder (vendor trumps library)