Top Banner
These are confidential sessions—please refrain from streaming, blogging, or taking pictures Session 216 Bringing Your iOS Apps to OS X Cortis Clark Software Engineer
180

Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Oct 18, 2019

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

These are confidential sessions—please refrain from streaming, blogging, or taking pictures

Session 216

Bringing Your iOS Apps to OS X

Cortis ClarkSoftware Engineer

Page 2: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

At a Glance

Page 3: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

At a Glance

1. Rethink your design

Page 4: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

At a Glance

1. Rethink your design2. Restructure your code

Page 5: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

At a Glance

1. Rethink your design2. Restructure your code3. Get started

Page 6: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Rethink Your Design

Page 7: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Rethink your app for OS XEmbrace the Platform

•Displays and windows

iOS OS X

Page 8: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Rethink your app for OS X

• Input devices

44 x 44

Embrace the Platform

Much More Precise

Page 9: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Rethink your app for OS XEmbrace the Platform

Page 10: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Rethink your app for OS XEmbrace the Platform

•Menus and keyboard shortcuts

Page 11: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Rethink your app for OS XEmbrace the Platform

•Menus and keyboard shortcuts•Undo and redo

Page 12: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Rethink your app for OS XEmbrace the Platform

•Menus and keyboard shortcuts•Undo and redo•Drag and drop

Page 13: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Rethink your app for OS XEmbrace the Platform

•Menus and keyboard shortcuts•Undo and redo•Drag and drop•Quick Look

Page 14: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Rethink your app for OS XEmbrace the Platform

•Menus and keyboard shortcuts•Undo and redo•Drag and drop•Quick Look• Spotlight

Page 15: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Restructure Your Code

Page 16: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Leverage Existing Knowledge

Page 17: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Leverage Existing Knowledge

•Design patterns

Page 18: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Leverage Existing Knowledge

•Design patterns• Xcode

Page 19: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Leverage Existing Knowledge

•Design patterns• Xcode• Languages and frameworks

Page 20: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Leverage Existing Knowledge

•Design patterns• Xcode• Languages and frameworks• Resources

Page 21: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Leverage Existing Knowledge

•Design patterns• Xcode• Languages and frameworks• Resources• Localizations

Page 22: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Technology StackiOS and OS X

iOS Equivalence OS X

Foundation

Text

Media

Cocoa

Core Foundation = Core Foundation

Foundation = Foundation

Core Data = Core Data

Core Text = Core Text

Core Graphics = Core Graphics

Core Animation = Core Animation

Core Image < Core Image

Core Audio < Core Audio

AV Foundation < AV Foundation

UIKit ~ AppKit

Page 23: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Technology StackiOS and OS X

iOS Equivalence OS X

Foundation

Text

Media

Cocoa

Core Foundation = Core Foundation

Foundation = Foundation

Core Data = Core Data

Core Text = Core Text

Core Graphics = Core Graphics

Core Animation = Core Animation

Core Image < Core Image

Core Audio < Core Audio

AV Foundation < AV Foundation

UIKit ~ AppKit

Page 24: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Technology StackiOS and OS X

iOS Equivalence OS X

Foundation

Text

Media

Cocoa

Core Foundation = Core Foundation

Foundation = Foundation

Core Data = Core Data

Core Text = Core Text

Core Graphics = Core Graphics

Core Animation = Core Animation

Core Image < Core Image

Core Audio < Core Audio

AV Foundation < AV Foundation

UIKit ~ AppKit

Page 25: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Technology StackiOS and OS X

iOS Equivalence OS X

Foundation

Text

Media

Cocoa

Core Foundation = Core Foundation

Foundation = Foundation

Core Data = Core Data

Core Text = Core Text

Core Graphics = Core Graphics

Core Animation = Core Animation

Core Image < Core Image

Core Audio < Core Audio

AV Foundation < AV Foundation

UIKit ~ AppKit

Page 26: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Technology StackiOS and OS X

iOS Equivalence OS X

Games Open GL ES < Open GL

Game Center = Game Center

SpriteKit = SpriteKit

Page 27: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Model View Controller

Model

Controller

Notify User ActionUpdate

View

Update

Page 28: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Model View Controller

Model

Controller

Notify User ActionUpdate

View

Update

Page 29: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migrating the Model

• Ensure clean model boundaries■ Mostly re-usable■ Model frameworks are cross-platform

Page 30: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Foundation, Core Foundation, Core Data etc.Model Frameworks

Page 31: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Foundation, Core Foundation, Core Data etc.Model Frameworks

• iOSNSMutableArray *myArray = [NSMutableArray arrayWithCapacity:10];[myArray addObject:@”WWDC 2013”];

Page 32: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Foundation, Core Foundation, Core Data etc.Model Frameworks

• iOSNSMutableArray *myArray = [NSMutableArray arrayWithCapacity:10];[myArray addObject:@”WWDC 2013”];

•OS XNSMutableArray *myArray = [NSMutableArray arrayWithCapacity:10];[myArray addObject:@”WWDC 2013”];

Page 33: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

32 Bit vs. 64 Bit

Page 34: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

32 Bit vs. 64 Bit

• Variably sized typesNSIntegerNSUInteger

Page 35: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

32 Bit vs. 64 Bit

• Variably sized typesNSIntegerNSUInteger

• Types of guaranteed sizeuint32_tint32_tuint64_tint64_t

Page 36: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Platform Specific Code

Page 37: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Platform Specific Code

• iOS only

Page 38: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Platform Specific Code

• iOS only#if TARGET_OS_IPHONE

Page 39: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Platform Specific Code

• iOS only#if TARGET_OS_IPHONE

•OS X only

Page 40: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Platform Specific Code

• iOS only#if TARGET_OS_IPHONE

•OS X only#if TARGET_OS_MAC && !TARGET_OS_IPHONE

Page 41: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Model View Controller

Model

Controller

Notify User ActionUpdate

View

Update

Page 42: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Model View Controller

Model

Controller

Notify User ActionUpdate

View

Update

Page 43: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Built-in control setMigrating the View

iOS OS X

Page 44: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UITableView vs. NSTableView

Page 45: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UITableView vs. NSTableView

• Similarities■ Data sources■ Reusable cells■ Animation

Page 46: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UITableView vs. NSTableView

• Similarities■ Data sources■ Reusable cells■ Animation

•Differences■ NSTableView has two variants (use view-based)■ Multiple columns■ Another control may be a better fit

Page 47: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

TableView DifferencesSelect an item in a list

iOS UITableView OS X NSPopupButton

Page 48: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

TableView DifferencesSelect an item in a list

iOS UITableView OS X NSPopupButton

Page 49: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

TableView DifferencesSelect an item in a list

iOS UITableView OS X NSPopupButton

Page 50: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

TableView DifferencesSelect an item in a list

iOS UITableView OS X NSButton(or StackView)

Page 51: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

TableView DifferencesSelect an item in a list

iOS UITableView OS X NSButton(or StackView)

Page 52: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

TableView DifferencesSelect an item in a list

iOS UITableView OS X NSButton(or StackView)

Page 53: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

TableView DifferencesSelect an item in a list

iOS UITableView OS X NSButton(or StackView)

Page 54: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

TableView DifferencesSelect an item in a list

iOS UITableView OS X NSButton(or StackView)

Page 55: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At
Page 56: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIView NSView

Page 57: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Receives and handles eventsReceives and handles events

Responsible for drawingResponsible for drawing

(0, 0) in upper left (0, 0) in lower left

Always has layer Opt-in to layers

Subviews can drawoutside view bounds

Subviews clip toview bounds

UIView NSView

Page 58: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Receives and handles eventsReceives and handles events

Responsible for drawingResponsible for drawing

(0, 0) in upper left (0, 0) in lower left

Always has layer Opt-in to layers

Subviews can drawoutside view bounds

Subviews clip toview bounds

UIView NSView

Page 59: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Receives and handles eventsReceives and handles events

Responsible for drawingResponsible for drawing

(0, 0) in upper left (0, 0) in lower left

Always has layer Opt-in to layers

Subviews can drawoutside view bounds

Subviews clip toview bounds

UIView NSView

Page 60: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Receives and handles eventsReceives and handles events

Responsible for drawingResponsible for drawing

(0, 0) in upper left (0, 0) in lower left

Always has layer Opt-in to layers

Subviews can drawoutside view bounds

Subviews clip toview bounds

UIView NSView

Page 61: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Receives and handles eventsReceives and handles events

Responsible for drawingResponsible for drawing

(0, 0) in upper left (0, 0) in lower left

Always has layer Opt-in to layers

Subviews can drawoutside view bounds

Subviews clip toview bounds

UIView NSView

Page 62: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

To match iOSDrawing Origins

- (BOOL)isFlipped { return YES;}

UIView

NSView

Page 63: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

To match iOSDrawing Origins

- (BOOL)isFlipped { return YES;}

UIView NSView

Page 64: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

AppKit Flipped Views

Views that are flipped by default

NSButton

NSScrollView

NSSplitView

NSTabView

NSTableView

Page 65: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Layer Backed Views

Page 66: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Layer Backed Views

• Pros■ Smoother animation■ CAFilter

• Cons■ More resource intensive

Page 67: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Layer Backed Views

Page 68: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

•UIView backed by layer

Layer Backed Views

Page 69: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

•UIView backed by layer•NSView can opt-in to layer backing

Layer Backed Views

Page 70: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

•UIView backed by layer•NSView can opt-in to layer backing

■ In code

Layer Backed Views

Page 71: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

•UIView backed by layer•NSView can opt-in to layer backing

■ In code[aView setWantsLayer:YES];

Layer Backed Views

Page 72: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

•UIView backed by layer•NSView can opt-in to layer backing

■ In code[aView setWantsLayer:YES];

■ Using Xcode

Layer Backed Views

Page 73: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

•UIView backed by layer•NSView can opt-in to layer backing

■ In code[aView setWantsLayer:YES];

■ Using Xcode

Layer Backed Views

Page 74: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

•UIView backed by layer•NSView can opt-in to layer backing

■ In code[aView setWantsLayer:YES];

■ Using Xcode

Layer Backed Views

Page 75: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Animation

Page 76: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Animation

• iOS

Page 77: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Animation

• iOS[UIView animateWithDuration:1.0 animations:^{

Page 78: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Animation

• iOS[UIView animateWithDuration:1.0 animations:^{ aView.frame = CGRectMake(100.0,100.0,300.0,300.0);

Page 79: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Animation

• iOS[UIView animateWithDuration:1.0 animations:^{ aView.frame = CGRectMake(100.0,100.0,300.0,300.0);}];

Page 80: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Animation

• iOS[UIView animateWithDuration:1.0 animations:^{ aView.frame = CGRectMake(100.0,100.0,300.0,300.0);}];

•OS X uses animation proxies

Page 81: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Animation

• iOS[UIView animateWithDuration:1.0 animations:^{ aView.frame = CGRectMake(100.0,100.0,300.0,300.0);}];

•OS X uses animation proxiesaView.animator.frame = NSMakeRect(100.0,100.0,300.0,300.0);

Page 82: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Events

Page 83: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UITapGestureRecognizer replacementEvents

Page 84: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UITapGestureRecognizer replacementEvents

- (void)mouseUp:(NSEvent *)theEvent { // Handle click}

Page 85: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UILongPressGestureRecognizer replacementEvents

- (void)mouseDown:(NSEvent *)theEvent { self.longPressTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(doSomething:) userInfo:nil repeats:NO];}

- (void)mouseUp:(NSEvent *)theEvent { [self.longPressTimer invalidate];}

- (void)doSomething:(NSTimer*)theTimer { // perform long press action}

99%Use a Right Click Instead

Page 86: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UILongPressGestureRecognizer replacementEvents

- (void)mouseDown:(NSEvent *)theEvent { self.longPressTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(doSomething:) userInfo:nil repeats:NO];}

- (void)mouseUp:(NSEvent *)theEvent { [self.longPressTimer invalidate];}

- (void)doSomething:(NSTimer*)theTimer { // perform long press action}

99%Use a Right Click Instead

Page 87: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UILongPressGestureRecognizer replacementEvents

- (NSMenu *)menuForEvent:(NSEvent *)theEvent { // return contextual menu }

Page 88: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIPanGestureRecognizer replacementEvents

- (void)mouseDown:(NSEvent *)theEvent { // Record drag start location}

- (void)mouseDragged:(NSEvent *)theEvent { // Move view to new location}

- (void)mouseUp:(NSEvent *)theEvent { // Cleanup drag code}

Page 89: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIPanGestureRecognizer replacementEvents

- (void)mouseDown:(NSEvent *)theEvent{ NSSize dragOffset = NSMakeSize(0.0, 0.0); // parameter ignored NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSDragPboard]; [pb clearContents]; [pb writeObjects:@[self.image]]; [self dragImage:self.image at:self.imageLocation offset:dragOffset event:theEvent pasteboard:pb source:self slideBack:YES]; return;}

Page 90: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIPanGestureRecognizer replacementEvents

- (void)mouseDown:(NSEvent *)theEvent{ NSSize dragOffset = NSMakeSize(0.0, 0.0); // parameter ignored NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSDragPboard]; [pb clearContents]; [pb writeObjects:@[self.image]]; [self dragImage:self.image at:self.imageLocation offset:dragOffset event:theEvent pasteboard:pb source:self slideBack:YES]; return;}

Page 91: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIPanGestureRecognizer replacementEvents

- (void)mouseDown:(NSEvent *)theEvent{ NSSize dragOffset = NSMakeSize(0.0, 0.0); // parameter ignored NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSDragPboard]; [pb clearContents]; [pb writeObjects:@[self.image]]; [self dragImage:self.image at:self.imageLocation offset:dragOffset event:theEvent pasteboard:pb source:self slideBack:YES]; return;}

Page 92: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIPanGestureRecognizer replacementEvents

- (void)mouseDown:(NSEvent *)theEvent{ NSSize dragOffset = NSMakeSize(0.0, 0.0); // parameter ignored NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSDragPboard]; [pb clearContents]; [pb writeObjects:@[self.image]]; [self dragImage:self.image at:self.imageLocation offset:dragOffset event:theEvent pasteboard:pb source:self slideBack:YES]; return;}

Page 93: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Model View Controller

Model

Controller

Notify User ActionUpdate

View

Update

Page 94: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Model View Controller

Model

Controller

Notify User ActionUpdate

View

Update

Page 95: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migrating the Controller

Page 96: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migrating the Controller

•UIViewController ≠ NSViewController

Page 97: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migrating the Controller

•UIViewController ≠ NSViewController•No NSNavigationController

Page 98: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migrating the Controller

•UIViewController ≠ NSViewController•No NSNavigationController• Bindings

Page 99: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migrating the Controller

•UIViewController ≠ NSViewController•No NSNavigationController• Bindings•NSDocument awesomeness

Page 100: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIDocument vs. NSDocument

Page 101: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIDocument vs. NSDocument

• Similarities

Page 102: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIDocument vs. NSDocument

• Similarities■ Saves and loads

Page 103: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIDocument vs. NSDocument

• Similarities■ Saves and loads■ Undo support

Page 104: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIDocument vs. NSDocument

• Similarities■ Saves and loads■ Undo support■ iCloud

Page 105: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIDocument vs. NSDocument

• Similarities■ Saves and loads■ Undo support■ iCloud

•NSDocument extras

Page 106: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIDocument vs. NSDocument

• Similarities■ Saves and loads■ Undo support■ iCloud

•NSDocument extras■ File, Edit, and Window menus

Page 107: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIDocument vs. NSDocument

• Similarities■ Saves and loads■ Undo support■ iCloud

•NSDocument extras■ File, Edit, and Window menus■ UI for opening and saving files

Page 108: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIDocument vs. NSDocument

• Similarities■ Saves and loads■ Undo support■ iCloud

•NSDocument extras■ File, Edit, and Window menus■ UI for opening and saving files■ Versions

Page 109: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIDocument vs. NSDocument

• Similarities■ Saves and loads■ Undo support■ iCloud

•NSDocument extras■ File, Edit, and Window menus■ UI for opening and saving files■ Versions■ Plus more…

Page 110: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

DemoShapeArt—A case study

Dan SchimpfDemo Monkey

Page 111: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migration Strategies

Page 112: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At
Page 113: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIColor

Page 114: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

UIColor NSColor

Page 115: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

UIColor *aColor = [UIColor redColor];

[aColor set];

NSColor *aColor = [NSColor redColor];

[aColor set];

iOS OS X

Page 116: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

UIColor *aColor = [UIColor redColor];

[aColor set];

NSColor *aColor = [NSColor redColor];

[aColor set];

iOS OS X

Page 117: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

UIColor *aColor = [UIColor redColor];

[aColor set];

NSColor *aColor = [NSColor redColor];

[aColor set];

iOS OS X

Page 118: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

// Center new view on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

CGRect frame = CGRectMake(x,y,w,h);UIView *view = [[UIView alloc] initWithFrame:frame];

// Place new view below others[self insertSubview:view atIndex:0];

// Center new view of on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

NSRect frame = NSMakeRect(x,y,w,h);NSView *view = [[NSView alloc] initWithFrame:frame];

// Place new view below others[self addSubview:view positioned:NSWindowBelow relativeTo:nil];

iOS OS X

Page 119: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

// Center new view on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

CGRect frame = CGRectMake(x,y,w,h);UIView *view = [[UIView alloc] initWithFrame:frame];

// Place new view below others[self insertSubview:view atIndex:0];

// Center new view of on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

NSRect frame = NSMakeRect(x,y,w,h);NSView *view = [[NSView alloc] initWithFrame:frame];

// Place new view below others[self addSubview:view positioned:NSWindowBelow relativeTo:nil];

iOS OS X

Page 120: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

// Center new view on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

CGRect frame = CGRectMake(x,y,w,h);UIView *view = [[UIView alloc] initWithFrame:frame];

// Place new view below others[self insertSubview:view atIndex:0];

// Center new view of on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

NSRect frame = NSMakeRect(x,y,w,h);NSView *view = [[NSView alloc] initWithFrame:frame];

// Place new view below others[self addSubview:view positioned:NSWindowBelow relativeTo:nil];

iOS OS X

Page 121: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

// Center new view on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

CGRect frame = CGRectMake(x,y,w,h);UIView *view = [[UIView alloc] initWithFrame:frame];

// Place new view below others[self insertSubview:view atIndex:0];

// Center new view of on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

NSRect frame = NSMakeRect(x,y,w,h);NSView *view = [[NSView alloc] initWithFrame:frame];

// Place new view below others[self addSubview:view positioned:NSWindowBelow relativeTo:nil];

iOS OS X

Page 122: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

// Center new view on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

CGRect frame = CGRectMake(x,y,w,h);UIView *view = [[UIView alloc] initWithFrame:frame];

// Place new view below others[self insertSubview:view atIndex:0];

// Center new view of on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

NSRect frame = NSMakeRect(x,y,w,h);NSView *view = [[NSView alloc] initWithFrame:frame];

// Place new view below others[self addSubview:view positioned:NSWindowBelow relativeTo:nil];

iOS OS X

Page 123: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

// Center new view on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

CGRect frame = CGRectMake(x,y,w,h);UIView *view = [[UIView alloc] initWithFrame:frame];

// Place new view below others[self insertSubview:view atIndex:0];

// Center new view of on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

NSRect frame = NSMakeRect(x,y,w,h);NSView *view = [[NSView alloc] initWithFrame:frame];

// Place new view below others[self addSubview:view positioned:NSWindowBelow relativeTo:nil];

iOS OS X

Page 124: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

// Center new view on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

CGRect frame = CGRectMake(x,y,w,h);UIView *view = [[UIView alloc] initWithFrame:frame];

// Place new view below others[self insertSubview:view atIndex:0];

// Center new view of on selfCGFloat x = (self.bounds.width - w)/2;CGFloat y = (self.bounds.height - h)/2;

NSRect frame = NSMakeRect(x,y,w,h);NSView *view = [[NSView alloc] initWithFrame:frame];

// Place new view below others[self addSubview:view positioned:NSWindowBelow relativeTo:nil];

iOS OS X

Page 125: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

Page 126: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

• Pros■ Flexibility

Page 127: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

• Pros■ Flexibility

• Cons■ Code duplication

■ Greater maintenance cost■ Greater testing cost

Page 128: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Mirrored codeMigration Strategies

• Pros■ Flexibility

• Cons■ Code duplication

■ Greater maintenance cost■ Greater testing cost

•When to use?■ Heavily platform dependent code

Page 129: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Use common frameworkMigration Strategies

Common Framework

iOS Framework OS X Framework

Page 130: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Use common frameworkMigration Strategies

CIColor *aColor = [CIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];

CIImage *image = [CIImage imageWithColor:aColor];

iOS and OS X

Page 131: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Use common frameworkMigration Strategies

Page 132: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Use common frameworkMigration Strategies

• Lower level frameworks are cross-platform

Page 133: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Use common frameworkMigration Strategies

• Lower level frameworks are cross-platform• Pros

■ Maximizes code reuse■ Most robust■ Minimal maintenance

Page 134: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Use common frameworkMigration Strategies

• Lower level frameworks are cross-platform• Pros

■ Maximizes code reuse■ Most robust■ Minimal maintenance

• Cons■ Refactoring■ Less functionality

Page 135: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Use common frameworkMigration Strategies

• Lower level frameworks are cross-platform• Pros

■ Maximizes code reuse■ Most robust■ Minimal maintenance

• Cons■ Refactoring■ Less functionality

•When to use?■ If common framework provides needed functionality

Page 136: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

Adapter

Common Source

iOS OSX

Page 137: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter pattern*Migration Strategies

Adapter*

Common Source

iOS OSX

Page 138: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

// XPlatformColor.h

#if TARGET_OS_IPHONE // iOS

@interface XPlatformColor : NSObject {   UIColor *_underlyingColor;}

#elif TARGET_OS_MAC && !TARGET_OS_IPHONE // OS X

@interface XPlatformColor : NSObject {   NSColor *_underlyingColor;}

#endif

Page 139: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

// XPlatformColor.h

#if TARGET_OS_IPHONE // iOS

@interface XPlatformColor : NSObject {   UIColor *_underlyingColor;}

#elif TARGET_OS_MAC && !TARGET_OS_IPHONE // OS X

@interface XPlatformColor : NSObject {   NSColor *_underlyingColor;}

#endif

Page 140: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

// XPlatformColor.h

#if TARGET_OS_IPHONE // iOS

@interface XPlatformColor : NSObject {   UIColor *_underlyingColor;}

#elif TARGET_OS_MAC && !TARGET_OS_IPHONE // OS X

@interface XPlatformColor : NSObject {   NSColor *_underlyingColor;}

#endif

Page 141: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

Page 142: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

• Pros

Page 143: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

• Pros■ Flexible

Page 144: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

• Pros■ Flexible■ Maximizes code reuse

Page 145: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

• Pros■ Flexible■ Maximizes code reuse■ Simplified interface

Page 146: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

• Pros■ Flexible■ Maximizes code reuse■ Simplified interface■ Requires less maintenance

Page 147: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

• Pros■ Flexible■ Maximizes code reuse■ Simplified interface■ Requires less maintenance

• Cons

Page 148: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

• Pros■ Flexible■ Maximizes code reuse■ Simplified interface■ Requires less maintenance

• Cons■ Additional code

Page 149: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

• Pros■ Flexible■ Maximizes code reuse■ Simplified interface■ Requires less maintenance

• Cons■ Additional code

•When to use?

Page 150: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter patternMigration Strategies

• Pros■ Flexible■ Maximizes code reuse■ Simplified interface■ Requires less maintenance

• Cons■ Additional code

•When to use?■ Underlying APIs significantly different

Page 151: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

#if TARGET_OS_IPHONE

#define XPlatformColor UIColor // iOS

#elif TARGET_OS_MAC && !TARGET_OS_IPHONE

#define XPlatformColor NSColor // OS X

#endif

Page 152: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

#if TARGET_OS_IPHONE

#define XPlatformColor UIColor // iOS

#elif TARGET_OS_MAC && !TARGET_OS_IPHONE

#define XPlatformColor NSColor // OS X

#endif

Page 153: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

#if TARGET_OS_IPHONE

#define XPlatformColor UIColor // iOS

#elif TARGET_OS_MAC && !TARGET_OS_IPHONE

#define XPlatformColor NSColor // OS X

#endif

Page 154: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

Page 155: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros

Page 156: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros■ Almost no new code

Page 157: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros■ Almost no new code■ Compile time error checking

Page 158: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros■ Almost no new code■ Compile time error checking

• Cons

Page 159: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros■ Almost no new code■ Compile time error checking

• Cons■ Only for supported classes!

Page 160: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros■ Almost no new code■ Compile time error checking

• Cons■ Only for supported classes!

■ UIColor and NSColor

Page 161: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros■ Almost no new code■ Compile time error checking

• Cons■ Only for supported classes!

■ UIColor and NSColor■ UIFont and NSFont

Page 162: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros■ Almost no new code■ Compile time error checking

• Cons■ Only for supported classes!

■ UIColor and NSColor■ UIFont and NSFont■ UIImage and NSImage

Page 163: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros■ Almost no new code■ Compile time error checking

• Cons■ Only for supported classes!

■ UIColor and NSColor■ UIFont and NSFont■ UIImage and NSImage■ UIBezierPath and NSBezierPath

Page 164: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros■ Almost no new code■ Compile time error checking

• Cons■ Only for supported classes!

■ UIColor and NSColor■ UIFont and NSFont■ UIImage and NSImage■ UIBezierPath and NSBezierPath

■ Limited API coverage within supported classes

Page 165: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Adapter using #defineMigration Strategies

• Pros■ Almost no new code■ Compile time error checking

• Cons■ Only for supported classes!

■ UIColor and NSColor■ UIFont and NSFont■ UIImage and NSImage■ UIBezierPath and NSBezierPath

■ Limited API coverage within supported classes■ Requires custom archiving

Page 166: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migration Testing

Page 167: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migration Testing

• Compiling code ≠ correct code

Page 168: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migration Testing

• Compiling code ≠ correct code•Unit testing

Page 169: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migration Testing

• Compiling code ≠ correct code•Unit testing•Manual testing

Page 170: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migration Testing

• Compiling code ≠ correct code•Unit testing•Manual testing• Beta testing

Page 171: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Migration Testing

• Compiling code ≠ correct code•Unit testing•Manual testing• Beta testing• Testing plans

Page 172: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

DemoFinished OS X version

Dan SchimpfDemo Monkey

Page 173: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Take Home Message

Page 174: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Take Home Message

1. Rethink your design

Page 175: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Take Home Message

1. Rethink your design2. Restructure your code

Page 176: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Take Home Message

1. Rethink your design2. Restructure your code3. Get started

Page 177: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

More Information

Jake BehrensApp Frameworks [email protected]

DocumentationAppKithttp://developer.apple.com/mac

Mac OS X Human Interface Guidelineshttp://developer.apple.com/ue

Apple Developer Forumshttp://devforums.apple.com

Page 178: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Taking Control of Auto Layout in Xcode 5 PresidioWednesday 10:15AM

Best Practices for Cocoa Animation MarinaWednesday 2:00PM

Introduction to Sprite Kit PresidioWednesday 11:30AM

Introducing Text Kit PresidioWednesday 2:00PM

Related Sessions

Page 179: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At

Cocoa Animations, Drawing, and Cocoa Lab Frameworks Lab AFriday 9:00AM

NSTableView, NSView, and Cocoa Lab Frameworks Lab AThursday 10:15AM

Labs

iOS to OS X Conversion Lab Frameworks Lab AThursday 11:30AM

Page 180: Bringing Your iOS Apps to OS X - devstreaming-cdn.apple.com · Bringing Your iOS Apps to OS X Cortis Clark Software Engineer. At a Glance. At a Glance 1. Rethink your design . At