Slide 1

Slide 1 text

Objective-C Worst Practices VXXXXXXXXXXZ And How To Avoid Them

Slide 2

Slide 2 text

• Aesthetics • Shibboleths • Verbosity • Responsibility • Privilege • Logistics

Slide 3

Slide 3 text

Aesthetics

Slide 4

Slide 4 text

Formatting • Consistency • Consistency • Consistency

Slide 5

Slide 5 text

• Tabs vs. Spaces • 2 / 4 Space Tabs • Space after -, (, or ) • Newline after { or }

Slide 6

Slide 6 text

Does Not Matter

Slide 7

Slide 7 text

GitHub Objective-C Style Guide https://github.com/github/ objective-c-conventions

Slide 8

Slide 8 text

#Pragma #pragma mark - UIViewController

Slide 9

Slide 9 text

#pragma Sections • initializers • overridden subclass methods • protocols

Slide 10

Slide 10 text

typedef-ing Block Parameters

Slide 11

Slide 11 text

- (void)performBlock:(XXBlock)block

Slide 12

Slide 12 text

- (void)performBlock: (void (^)(NSError *error))block

Slide 13

Slide 13 text

Shibboleths

Slide 14

Slide 14 text

Gileadites Ephraimites ʃɪbəlεθ sɪbəlεθ

Slide 15

Slide 15 text

Deutsch English ɪx iʃ

Slide 16

Slide 16 text

Ruby Ruby Objective-C underscore_variable_name camelCaseVariableName def short(options = {}) - (void)longMethodWithParameter: andAnotherParameter: CAPITALIZED_CONSTANT kCamelCaseConstant Module::Class MNClass

Slide 17

Slide 17 text

Java Java AbstractLinkedHashMapFactorySingletonBean Objective-C NSAbstractLinkedHashMapFactorySingletonBean

Slide 18

Slide 18 text

Java Java AbstractLinkedHashMapFactorySingletonBean Objective-C NSDictionary

Slide 19

Slide 19 text

Using Strings Instead of Enumerated Constants

Slide 20

Slide 20 text

Ruby Ruby Objective-C :symbol kNSConstant

Slide 21

Slide 21 text

Bonus Points NS_ENUM NS_OPTIONS

Slide 22

Slide 22 text

Using Literal Strings Instead of Constants

Slide 23

Slide 23 text

@{@"error": @"Foo Bar Baz"}

Slide 24

Slide 24 text

NSString * const kErrorKey = @"error"; @{kErrorKey: @"Foo Bar Baz"}

Slide 25

Slide 25 text

Using Literal Strings Instead of Localized Strings

Slide 26

Slide 26 text

NSLocalizedString()

Slide 27

Slide 27 text

Not Using Foundation Built-in Types

Slide 28

Slide 28 text

• NSSet • NSCache • NSLocale • NSSortDescriptor • NSPredicate • NSURL • NSURLRequest • NSURLResponse • NSURLCredential Foundation Favorites

Slide 29

Slide 29 text

( N S < ❤

Slide 30

Slide 30 text

Responsibility

Slide 31

Slide 31 text

T M I oo uch nfo

Slide 32

Slide 32 text

X X X X Censored

Slide 33

Slide 33 text

Private Category @interface FooViewController () ... @end

Slide 34

Slide 34 text

Private Category @interface FVC ()

Slide 35

Slide 35 text

• NSOperationQueue • NSURLProtocol • NSPersistentStoreCoordinator

Slide 36

Slide 36 text

Mutable Properties X X X X Censored

Slide 37

Slide 37 text

Proxying Complex Internal Objects

Slide 38

Slide 38 text

cell.text = @"Guten Tag!";

Slide 39

Slide 39 text

cell.text = @"Guten Tag!"; cell.textColor = [...]; cell.font = [...];

Slide 40

Slide 40 text

UILabel "I got this"

Slide 41

Slide 41 text

cell.textLabel.text = @"Guten Tag!";

Slide 42

Slide 42 text

Privilege

Slide 43

Slide 43 text

No Classes should require insider knowledge to use

Slide 44

Slide 44 text

Delegates

Slide 45

Slide 45 text

Block Callbacks

Slide 46

Slide 46 text

Notifications

Slide 47

Slide 47 text

Logistics

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

platform :ios, “5.0” pod “AFNetworking” pod “AFIncrementalStore”

Slide 50

Slide 50 text

MAINTAIN SANITY AND USE COCOAPODS

Slide 51

Slide 51 text

Open-Source Projects

Slide 52

Slide 52 text

Not Having README Screenshots Sample Project or and

Slide 53

Slide 53 text

?

Slide 54

Slide 54 text

Please, please, stop making Swiss Army Knife category Libraries

Slide 55

Slide 55 text

• NSArray -firstObject • NSString -URL • UIView -setLeft:/-setSize:/etc. • UIImage -scaledImage...

Slide 56

Slide 56 text

tl;dr

Slide 57

Slide 57 text

• Make your code sparkle • Follow Apple's conventions • Delegate responsibilities • Use CocoaPods