Slide 1

Slide 1 text

Building libraries for iOS Going native Alexander Dodatko 2014

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

The standard library saves programmers from having to reinvent the wheel. Bjarne Stroustrup http://bit.ly/1iqZ3JO

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Code Reuse is Important

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

March 2008

Slide 8

Slide 8 text

http://engt.co/1pOLKH9

Slide 9

Slide 9 text

The fastest code is the code that reaches the market first

Slide 10

Slide 10 text

Nobody Cares

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

August 2011

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

pod install SomeAwesomeLibXYZ

Slide 18

Slide 18 text

Except...

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Typical Workflow

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Our own Busyness Logic

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

In-Place Editing

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Modular Architecture Benefits Code Reuse Test Coverage Easier to Apply Changes

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Going Native

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

--no-integrate

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Not Just Library Target

Slide 38

Slide 38 text

#import #import "AFHTTPRequestOperation.h" VS

Slide 39

Slide 39 text

#import "AFHTTPRequestOperation.h" For Implementation Files

Slide 40

Slide 40 text

#import For Public Headers

Slide 41

Slide 41 text

Incapsulation

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

#import #import

Slide 44

Slide 44 text

Static Framework for iOS

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

CFBundleDevelopmentRegion English CFBundleIdentifier org.ocmock CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType FMWK CFBundleSignature ???? CFBundleVersion 2.2.3

Slide 47

Slide 47 text

Drag & Drop

Slide 48

Slide 48 text

Framework Search Path is updated by Xcode

Slide 49

Slide 49 text

Frameworks Reduce Compilation Time

Slide 50

Slide 50 text

CocoaPods Makes you Care about Versioning

Slide 51

Slide 51 text

For Distribution For Development and Unit Testing

Slide 52

Slide 52 text

For You For End Users

Slide 53

Slide 53 text

Library Dependencies and Linker

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Never Link Libraries into Other Libraries

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Same Approach for Unit Tests

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

All Testable Code Should be in libraries

Slide 61

Slide 61 text

Use Precompiled Headers

Slide 62

Slide 62 text

// Pure C headers go here #include #ifdef __cplusplus // Pure C++ headers go here #include #endif #ifdef __OBJC__ // Objective-C headers go here #import #ifdef __cplusplus #import "MyObjectiveCppClass.h" #endif #endif

Slide 63

Slide 63 text

But I do not Need C++

Slide 64

Slide 64 text

NSDictionary* errorMessages; NSLog( @"%@", errorMessages[ @( errorCode ) ] ); Print Message for Low Level Error

Slide 65

Slide 65 text

std::map< NSInteger, NSString* > errorMessages; NSLog( @"%@", errorMessages[ errorCode ] ); C++ ===> No Boxing

Slide 66

Slide 66 text

Scoped Guard

Slide 67

Slide 67 text

void bad(const char* p) { FILE* fh = fopen(p,"r"); // acquire // use f if ( someCondition ) { // Oops! File handle leaks return; } fclose( fh ); // release }

Slide 68

Slide 68 text

void good(const char* p) { FILE* fh = fopen(p,"r"); // acquire // the block to perform cleanup actions GuardCallbackBlock releaseBlock_ = ^void( void ) { fclose( fh ); }; // creating a guard ObjcScopedGuard guard( releaseBlock_ ); if ( someCondition ) { // Now the scoped guard will release the resource return; } }

Slide 69

Slide 69 text

Exception-Safe Resource Deallocation

Slide 70

Slide 70 text

malloc() std::vector Vector as a Scoped Guard Memory

Slide 71

Slide 71 text

Let's Recap

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

#import For Public Headers

Slide 74

Slide 74 text

For Distribution For Development and Unit Testing

Slide 75

Slide 75 text

Native Rulezzz Alexander Dodatko @dodikk88