-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add iOS and Objective-C to existing guides
* Add iOS to Best Practices * Add iOS to Style Guidelines * Add iOS to Protocol * Add sample Objective-C code
- Loading branch information
1 parent
c4bd004
commit d4809ea
Showing
5 changed files
with
151 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#import "Alpha.h" | ||
#import "Beta.h" | ||
|
||
// Use @interface extensions for private properties | ||
@interface ClassName () <Protocols> | ||
|
||
// Keep @properties grouped together by function | ||
@property (strong, nonatomic) IBOutlet UISearchBar *searchBar; | ||
@property (strong, nonatomic) IBOutlet UITableView *tableView; | ||
|
||
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext; | ||
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController; | ||
|
||
@property (strong, nonatomic, readonly) TBObject *someObject; | ||
|
||
@end | ||
|
||
// Use static NSString points to consts for string constants | ||
static NSString *const ConstantName = @"Constant"; | ||
|
||
// Prepend constants with 'k' when being used as keys | ||
static NSString *const kFirstName = @"FirstName"; | ||
|
||
@implementation ClassName | ||
|
||
/* | ||
- Use #pragma mark to organize code by function | ||
- Use descriptive names for #pragma mark | ||
- Use class names if overriding or implementing protocol methods | ||
*/ | ||
#pragma mark - Initialization | ||
|
||
- (id)initWithCoder:(NSCoder *)aDecoder | ||
{ | ||
self = [super initWithCoder:aDecoder]; | ||
|
||
// Return early if conditions prohibit the intended function of the method | ||
// Use conditionals for exceptional cases | ||
// Keep the 'optimal' path non-indented | ||
if (!self) | ||
return nil; | ||
|
||
return self; | ||
} | ||
|
||
#pragma mark - UI | ||
|
||
// Opening brackets belong on the next line | ||
- (void)shuffleCards | ||
{ | ||
// Objective-C literals are your friend | ||
NSDictionary *themeColors = @{ kRedColor : [UIColor redColor], kBlueColor : [UIColor blueColor] }; | ||
NSArray *robots = @[ @"Ralph", @"Bender", @"The Iron Giant" ]; | ||
|
||
NSMutableArray *deckOfCards = [NSMutableArray arrayWithCapacity:52]; | ||
|
||
// Newlines before and after conditional blocks | ||
for (Card *card in deckOfCards) | ||
NSLog(@"%@", [card description]); | ||
|
||
Card *jokerCard = [Card joker]; | ||
[deckOfCards addObject:jokerCard]; | ||
|
||
// Use ! to check for nots. Comparing to 'nil' is redundant | ||
if (![creditCard isValid]) | ||
{ | ||
//... | ||
} | ||
} | ||
|
||
@end |