-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathsample.m
69 lines (51 loc) · 1.88 KB
/
sample.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#import "Alpha.h"
#import "Beta.h"
// Use @interface extensions for private properties
@interface TBClassName () <Protocols>
// Keep @properties grouped together by function
// Prefer strong IBOutlet references
@property (nonatomic) IBOutlet UISearchBar *searchBar;
@property (nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic) NSManagedObjectContext *managedObjectContext;
@property (nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, readonly) TBObject *someObject;
@end
// Use static NSString points to consts for string constants
static NSString *const TBConstantName = @"Constant";
static NSUInteger const TBNumberOfCardsInDeck = 52;
@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
- (instancetype)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 = @{RedColor: [UIColor redColor], BlueColor: [UIColor blueColor]};
NSArray *robots = @[@"Ralph", @"Bender", @"The Iron Giant"];
NSMutableArray *deckOfCards = [NSMutableArray array];
Card *jokerCard = [Card joker];
[deckOfCards addObject:jokerCard];
// Newlines before and after conditional blocks
for (Card *card in deckOfCards) {
NSLog(@"%@", [card description]);
}
// Use ! to check for nots. Comparing to 'nil' is redundant
if (![creditCard isValid]) {
//...
}
}
@end