Accessibility/Mac/ContributorGuide: Difference between revisions

Line 3: Line 3:
== Code Style ==
== Code Style ==


Our code style is based on Google's Objective C Style Guide
Our code style is based on [https://google.github.io/styleguide/objcguide.html Google's Objective C Style Guide], with a few exceptions and additions:
 
=== Method Declarations ===
 
Objective C is very flexible in its handling of method declarations. These rules should help remove ambiguity.
 
==== Always Declare Methods ====
 
Objective C does not require instance methods to have a declaration in the <code>@interface</code> block. If a method is defined in the <code>@implementation</code> block, it is accessible to any caller that knows of its signature. All methods should be declared. If they are public, they should be in the <code>@interface</code> block in the header file. If they are private they should be in a private class extension in the <code>mm</code> file.
 
For example, a header file might look like this:
 
<syntaxhighlight lang="Objective-C">
@interface Hello : NSObject
- (NSString*)world;
@end
</syntaxhighlight>
 
The <code>mm</code> file will look like this:
 
<syntaxhighlight lang="Objective-C">
@interface Hello()
- (NSNumber*)somethingElseThatIsPrivate;
@end
 
 
@implementation Hello
- (NSString*)world {
  return @"earth";
}
 
- (NSNumber*)somethingElseThatIsPrivate {
  return @(3);
}
 
// BAD! This method has not been declared
- (void)iAmNotDeclared:(NSString*)bah {
  NSLog(@"%@", bah);
}
@end
</syntaxhighlight>
 
==== Mark Methods "final" ====
 
A class cannot declare a method as final and prevent subclasses from overriding it. If a method should not be overridden by a subclass put the word "final" in a comment above the declaration. For example:
<syntaxhighlight lang="Objective-C">
// This method returns the word "bar"
// final
- (NSString*)foo;
</syntaxhighlight>
 
==== Mark Methods "override" ====
 
A subclass does not need to declare an overridden method as such. If a method is overriding a method from a superclass, or is implementing a method from a conformed protocol, put the word "override" in a comment above the declaration. For example:
 
<syntaxhighlight lang="Objective-C">
// This method returns the word "bear"
// override
- (NSString*)pooh;
</syntaxhighlight>


== Architecture and Design ==
== Architecture and Design ==
Confirmed users
198

edits