Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Objective-C Sins

Slide 3

Slide 3 text

sin 1 |sin| noun an immoral act considered to be a transgression against divine law: a sin in the eyes of God | the human capacity for sin. ! • an act regarded as a serious or regrettable fault, offense, or omission: he committed the unforgivable sin of refusing to give interviews | humorous : with air like this, it's a sin not to go out.

Slide 4

Slide 4 text

sin 1 |sin| noun an immoral act considered to be a transgression against divine law: a sin in the eyes of God | the human capacity for sin. ! • an act regarded as a serious or regrettable fault, offense, or omission: he committed the unforgivable sin of refusing to give interviews | humorous : with air like this, it's a sin not to go out.

Slide 5

Slide 5 text

@mb

Slide 6

Slide 6 text

matthew bischoff

Slide 7

Slide 7 text

matt

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Velocity Quotebook

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Sins

Slide 13

Slide 13 text

[object retainCount];

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Why not?

Slide 16

Slide 16 text

Object retainCount? Actual retainCount [NSNumber numberWithInt:1] 1 2 @"Matt" 1 1152921504606846975 [NSString stringWithString:@"Matt"] 1 1152921504606846975

Slide 17

Slide 17 text

Key-Value Observing

Slide 18

Slide 18 text

Key-Value Observing has the worst API in all of Cocoa. It’s awkward, verbose, and confusing. Mattt Thompson

Slide 19

Slide 19 text

“Stringly Typed”

Slide 20

Slide 20 text

Refactoring is scary.

Slide 21

Slide 21 text

Throws Exceptions

Slide 22

Slide 22 text

ARC == garbage collection

Slide 23

Slide 23 text

You still have to pay attention.

Slide 24

Slide 24 text

. Syntax [ ] Syntax

Slide 25

Slide 25 text

What’s the obvious thing to do, the easiest way to agree? Just do what the headers say. If it’s a property, treat it as such. If it’s not, don’t. ! And when in doubt, look it up. Brent Simmons

Slide 26

Slide 26 text

Dot syntax is for properties.

Slide 27

Slide 27 text

Bracket syntax is for methods.

Slide 28

Slide 28 text

UIColor.clearColor; array.count; object.hash;

Slide 29

Slide 29 text

More than 1 Class per file

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

performSelector: afterDelay:

Slide 32

Slide 32 text

It’s a crash waiting to happen.

Slide 33

Slide 33 text

Missing or improper reuse

Slide 34

Slide 34 text

Always reuse cells.

Slide 35

Slide 35 text

Don’t keep track of cells.

Slide 36

Slide 36 text

Architecture-dependent primitive types

Slide 37

Slide 37 text

int float double

Slide 38

Slide 38 text

NSInteger / NSUInteger CGFloat NSTimeInterval

Slide 39

Slide 39 text

Violating MVC

Slide 40

Slide 40 text

Models that do networking

Slide 41

Slide 41 text

Views that know about models

Slide 42

Slide 42 text

Controllers that do layout

Slide 43

Slide 43 text

NSDictionary

Slide 44

Slide 44 text

Not a replacement for a model

Slide 45

Slide 45 text

✨"

Slide 46

Slide 46 text

Magic numbers

Slide 47

Slide 47 text

Repeating yourself Repeating yourself Repeating yourself Repeating yourself Repeating yourself Repeating yourself

Slide 48

Slide 48 text

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system. Andy Hunt and Dave Thomas

Slide 49

Slide 49 text

if (taylorSwift) { taylorSwift.age = 22; }

Slide 50

Slide 50 text

id

Slide 51

Slide 51 text

Singletons

Slide 52

Slide 52 text

Blocking the main queue

Slide 53

Slide 53 text

Low level APIs

Slide 54

Slide 54 text

CoreFoundation CoreText CoreGraphics CoreAnimation

Slide 55

Slide 55 text

Foundation TextKit UIKit UIView Animations

Slide 56

Slide 56 text

@property (nonatomic, strong, readwrite) NSString *title;

Slide 57

Slide 57 text

@property (nonatomic) NSString *title;

Slide 58

Slide 58 text

@property NSString *title;

Slide 59

Slide 59 text

Warnings

Slide 60

Slide 60 text

Unused Variable ‘sin’ !

Slide 61

Slide 61 text

Unused Variable ‘sin’ !

Slide 62

Slide 62 text

Public and readwrite

Slide 63

Slide 63 text

Missing #pragma marks

Slide 64

Slide 64 text

#pragma mark - NSObject ! - (void)dealloc {} ! #pragma mark - UIViewController ! - (void)viewDidLoad {} ! #pragma mark - LCKDocumentsTableViewController ! - (void)setupRefreshControl {}

Slide 65

Slide 65 text

Bad names

Slide 66

Slide 66 text

UIImage *img; UIButton *btn; NSString *str; NSArray *arr; NSDictionary *dict; NSInteger i;

Slide 67

Slide 67 text

UIImage *avatar; UIButton *signupButton; NSString *name; NSArray *people; NSDictionary *userInfo; NSInteger count;

Slide 68

Slide 68 text

Two-letter prefixes

Slide 69

Slide 69 text

NS UI CG CA AC ST XC SK MF AD

Slide 70

Slide 70 text

Two-letter prefixes…are reserved by Apple for use in framework classes. ! Your own classes should use three letter prefixes.

Slide 71

Slide 71 text

Inconsistent style

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

Not overriding the designated initializer

Slide 74

Slide 74 text

- (instancetype)initWithPerson:(LCKPerson *)person { self = [super initWithStyle:UITableViewStylePlain]; if (self) { _person = person; _dataStore = [NSMutableDictionary dictionary]; } return self; }

Slide 75

Slide 75 text

- (id)initWithStyle:(UITableViewStyle)style { return [self initWithPerson:nil]; } ! - (instancetype)initWithPerson:(LCKPerson *)person { self = [super initWithStyle:UITableViewStylePlain]; if (self) { _person = person; _dataStore = [NSMutableDictionary dictionary]; } return self; }

Slide 76

Slide 76 text

UITapGestureRecognizer

Slide 77

Slide 77 text

Just use a UIButton.

Slide 78

Slide 78 text

UISwipeGestureRecognizer

Slide 79

Slide 79 text

Just use a UIPanGestureRecognizer.

Slide 80

Slide 80 text

Inaccessibility

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

Property Description Example accessibilityLabel Identifies the accessibility element, but does not include the type of the control or view “Share” accessibilityValue The value is a localized string that contains the current value of an element “35 %” accessibilityHint Description of the result of performing an action on the element. “Selects the message”

Slide 83

Slide 83 text

Missing Localization

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

// Unnecessary comments

Slide 86

Slide 86 text

Comments explain why. Not what or how.

Slide 87

Slide 87 text

true && false

Slide 88

Slide 88 text

YES and and NO

Slide 89

Slide 89 text

Profiling at the end

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

[[[[[too much] code] on] one] line]

Slide 92

Slide 92 text

#import

Slide 93

Slide 93 text

#define

Slide 94

Slide 94 text

retain cycles

Slide 95

Slide 95 text

Object Object strong

Slide 96

Slide 96 text

[self.queue addOperationWithBlock:^{ [self download]; }];

Slide 97

Slide 97 text

__weak typeof(self) weakSelf = self; [self.queue addOperationWithBlock:^{ [weakSelf download]; }];

Slide 98

Slide 98 text

(assign) delegates

Slide 99

Slide 99 text

self.webView.delegate = nil;

Slide 100

Slide 100 text

Blended layers

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

Mixing up nothing

Slide 104

Slide 104 text

nil, Nil, NULL, NSNull

Slide 105

Slide 105 text

Symbol Value Meaning NULL (void *)0 literal null value for C pointers nil (id)0 literal null value for Objective-C objects Nil (Class)0 literal null value for Objective-C classes NSNull [NSNull null] singleton object used to represent null

Slide 106

Slide 106 text

Ignoring crash logs

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

Special Thanks •Ash Furrow •Brent Simmons •Mattt Thompson •Brian Capps

Slide 109

Slide 109 text

Thank you.

Slide 110

Slide 110 text

Questions?