Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon...

19
Chameleon Getting your iOS app onto the Mac

Transcript of Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon...

Page 1: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

ChameleonGetting your iOS app onto the Mac

Page 2: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

What is it?

• UIKit for Mac OS X

• Implements same API as iOS

• Written by Sean Heber – @BigZaphod

• I’m the first guinea pig – @chockenberry

Page 3: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Why did we do it?

• Twitterrific for Mac

• About 50K lines of iOS code to rewrite

• And new code to maintain in parallel

• Started doing that…

• Then Sean got lazy… sort of.

Page 4: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Where are we now?

• Nine months later

• 90% of our code base is platform agnostic

• Simultaneous releases for Mac and iOS

• UI consistency across products

• 2x revenue from same code

Page 5: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

How can you use it?

• http://chameleonproject.org/

• Source code available on github

• API coverage about 60%

• No documentation

• Buy an expensive T-shirt

Page 6: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Documentation

• This talk is the starting point

• Thanks to @VTM_iPhone for video

• Not going to cover internals

• Talk about things we learned

• Porting guide for Mac

Page 7: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Make it Mac!

Documents

Windows

Menubar Status Item

Dock Icon

Toolbars

Page 8: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Where is UIKit?

Sidebar

Timeline

Timeline

Popovers

Page 9: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Refactoring

• It has to happen

• Multiple windows

• Menubar

• Application delegates differ

• Section 6.4 – “Apple sets a high bar”

Page 10: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

“Epic refactor is epic”

• 100+ files changed

• 1,100 word commit message for rev 3896

• Implemented application controller

• Actions & state managed by controller

• Controller is subclassed per platform

Page 11: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

TwitterrificController

• TwitterrificController base class

• TwitterrificController_iOS

• TwitterrificController_iPhone

• TwitterrificController_iPad

• TwitterrificController_Mac

Page 12: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Document Window

Document WindowController

UIKitView : NSView

UIViewController

Twitterrific Controller(Mac)

Timeline

Page 13: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Application Delegate

Application Delegate

UIViewController

Twitterrific Controller(iOS)

Timeline

Page 14: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

UIKitView

• Every UIKitView has a UIScreen

• 1:1 relationship with view and screen

• UIWindow accessor creates window

• Matches screen bounds

• Or do it yourself:myUIWindow.screen = myUIKitView.UIScreen;

Page 15: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

UIKitView- (void)setViewController:(UIViewController *)newViewController{ if (newViewController != viewController) { [viewController.view removeFromSuperview]; [viewController release]; viewController = [newViewController retain]; // unlike iOS, bounds can change often and radically viewController.view.autoresizingMask =

UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;

viewController.view.frame = self.UIWindow.bounds; [self.UIWindow addSubview:viewController.view]; // .. just like in iOS application delegate }}

Page 16: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Demo

Page 17: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Deficiencies

• Partial implementation (table view editing)

• Missing classes (switch and tab view)

• Nib loading: use -loadView

Page 18: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Deficiencies

• Accessibility

• Multi-touch and gesture recognizers

• WebView on 10.6 and Core Animation

• Subpixel anti-aliasing possible, but hard

Page 19: Chameleon - Iconfactoryfiles.iconfactory.net/craig/Chameleon.pdf · 2011. 4. 10. · Chameleon Getting your iOS app onto the Mac. What is it? • UIKit for Mac OS X

Q & A

http://chameleonproject.org/

http://files.iconfactory.net/craig/MultiApple.zip

Buy a T-shirt before April 20th!