Contribute
Three20 is a growing library of code. Here are a couple ways you can contribute to the project.
Via GitHub
If you have a fork of three20 on GitHub, then you can make a pull request from the GitHub interface.
Here's GitHub's pull request guide.
Contribute to three20.info
We've taken a rather odd approach to managing the three20.info website; we've open-sourced it on GitHub.
This means that you can fork the site, contribute your own articles, fixes, and updates, and we'll merge it back into the live site. It's basically a wiki, but without the complicated wiki backend.
All of the articles on the site are written with Markdown.
Fork the site on github.
Making Pull Requests on GitHub
If you want to improve the likelihood of your bug or feature being seen in mainline Three20, then follow this guideline for making pull requests.
For bugs:
- Include a reproduction scenario (also called a repro case). This should be either a detailed enough verbal description to recreate the bug in question, or, even better, a project that clearly shows the bug in question.
- If you have a solution, commit it to your personal Three20 repository on GitHub and then make a pull request. It's way easier than copy-pasting code and it ensures that your name will be attached to the fix.
For features:
- Provide detailed documentation for each new feature you provide, as well as the rationale for why you think it is necessary. Three20 has a lot of room to grow, but we need to ensure that it grows at a sustainable rate.
- If you don't intend to implement the feature, then document the steps required to implement the feature to the best of your knowledge. The more information you provide, the more likely your feature will be realized.
Source code style guidelines
Three20 uses a consistent style guideline throughout the entire code base. The various guidelines are presented below, separated into three sections: general guidelines, guidelines for .h files, and guidelines for .m files. Any code that does not follow these guidelines will not be merged into the mainline of Three20.
General Guidelines
Presented below are a site of guidelines that apply to every source file in Three20. This includes header (.h) and source (.m) files.
The Preamble
// // Copyright 2009-2010 Facebook // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. //
This is required at the top of each source file.
Imports
// UI #import "Three20/TTURLNavigatorPattern.h" #import "Three20/TTURLGeneratorPattern.h" // Core #import "Three20/TTGlobalCore.h" #import "Three20/TTCorePreprocessorMacros.h"
Group all imports into their logical Three20 section and prefix a given section with a comment stating which section you intend it to be. Remember, Three20 is split into Core, Network, Style, and UI.
The order of imports should always be the following:
- UI
- Style
- Network
- Core
- Apple Frameworks
Within a group, TTGlobal* headers should come first (e.g. TTGlobalCore.h).
Make an effort to include the minimal number of header files in each source file.
General style guidelines
The maximum line length is 100 characters.
Three20 uses spaces, not tabs.
Three20 uses two spaces for indentation.
Guidelines for .h files
Header Imports
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h>
Objects that don't inherit from any other TT* object should import the required
frameworks for the object in question. For example, TTURLRequestQueue needs Foundation.h in
order to inherit from NSObject and it needs UIKit.h for a CGFloat instance variable.
// Network #import "Three20/TTURLResponse.h"
For objects that inherit from other TT* objects, you don't need to import the frameworks.
Required classes/prototypes
@class TTURLRequest;
Unless you're inheriting from a class or implementing a protocol, it is adequate to provide an advance declaration of the class instead of importing the header file for the class.
Class definition
@interface TTModelViewController : TTViewController <TTModelDelegate> {
Three20 classes are always prefixed with TT. This is an example of an object that inherits from another Three20 class and implements a Three20 protocol.
@interface CustomModelViewController : TTViewController <
TTModelDelegate,
TTURLRequestDelegate
> {
If the object implements multiple protocols, split the protocol list into separate lines with the above format, one protocol on each line.
Class ivars
@private id _userInfo; NSMutableArray* _urls; id<TTActionSheetControllerDelegate> _delegate;
Instance variables (ivars) are explicitly declared private.
Ivar names are prefixed with an underscore (_).
Ivar names always begin with a lower-case letter and are camelCased.
Ivars must be grouped in some logical grouping.
Delegates and other protocol objects must be placed at the bottom of the ivar definitions.
Properties
/** * The maximum size of a download that is allowed. * * If a response reports a content length greater than the max, the download * will be cancelled. This is helpful for preventing excessive memory usage. * Setting this to zero will allow all downloads regardless of size. * * @default 150000 bytes */ @property (nonatomic) NSUInteger maxContentLength;
Due to our use of Doxygen to generate the API documentation, we use javadoc-style documentation syntax throughout the source. The first sentence of a comment will be the "summary" line shown in the API docs, and any subsequent lines will be in the "more details" section.
Unless you're certain of what you're doing, use nonatomic when declaring properties.
Be specific about the access level of the property. For example, properties that shouldn't
be modifiable outside of the class should be readonly.
Understand the difference between the retain, copy, and assign keywords. A general
rule of thumb is to use copy for NSStrings, retain for objects whose lifetime you want
to guarantee, and assign for delegates.
Guidelines for .m files
///////////////////////////////////////////////////////////////////////////////////////////////////
Before every method declaration there should be a comment line that is exactly 99 characters wide.
Before every class declaration there should be three of the above comment lines.
Initialization and deallocation
init and dealloc methods should always be the first methods in the class implementation.
- (id)init {
if (self = [self initWithTarget:nil]) {
}
return self;
}
Every class should have a designated initializer which calls the super class's designated
initializer. All other init methods for the class should call the local class's designated
initializer using self.