Top Banner
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Integrating Swift with Objective-C Tools Session 406 Anders Bertelrud Dave Schaefgen Jordan Rose
39

406 Integrating Swift With Objective c

Jul 19, 2016

Download

Documents

Intregrate swift with objective c
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: 406 Integrating Swift With Objective c

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Integrating Swift with Objective-C

Tools

Session 406 Anders Bertelrud

!

Dave Schaefgen!

Jordan Rose

Page 2: 406 Integrating Swift With Objective c

Introduction

Swift is Apple’s modern, type-safe language for Cocoa development

Page 3: 406 Integrating Swift With Objective c

Introduction

Swift is Apple’s modern, type-safe language for Cocoa development

But Objective-C remains a first-class citizen too

Page 4: 406 Integrating Swift With Objective c

Introduction

Swift is Apple’s modern, type-safe language for Cocoa development

But Objective-C remains a first-class citizen too

We do not want you to rewrite or stop improving your existing code!

Page 5: 406 Integrating Swift With Objective c

Introduction

Swift is Apple’s modern, type-safe language for Cocoa development

But Objective-C remains a first-class citizen too

We do not want you to rewrite or stop improving your existing code!

Xcode makes it easy to start adding Swift to your existing projects

Page 6: 406 Integrating Swift With Objective c

What You’ll Learn

Adding Swift code to your Objective-C application

Page 7: 406 Integrating Swift With Objective c

What You’ll Learn

Adding Swift code to your Objective-C application

Adding Swift code to your Objective-C model framework

Page 8: 406 Integrating Swift With Objective c

What You’ll Learn

Adding Swift code to your Objective-C application

Adding Swift code to your Objective-C model framework

Accessing a pure Swift framework from Objective-C

Page 9: 406 Integrating Swift With Objective c

What You’ll Learn

Adding Swift code to your Objective-C application

Adding Swift code to your Objective-C model framework

Accessing a pure Swift framework from Objective-C

Adopting well-established Cocoa patterns in Swift

Page 10: 406 Integrating Swift With Objective c

DemoSetting up the user interface

Anders Bertelrud

Page 11: 406 Integrating Swift With Objective c

What Did We Just Do?

Added Swift code to an Objective-C app

Page 12: 406 Integrating Swift With Objective c

What Did We Just Do?

Added Swift code to an Objective-C app

Subclassed a Cocoa class in Swift

Page 13: 406 Integrating Swift With Objective c

What Did We Just Do?

Added Swift code to an Objective-C app

Subclassed a Cocoa class in Swift

Used a Swift class in Interface Builder

Page 14: 406 Integrating Swift With Objective c

DemoIntegrating with existing code

Dave Schaefgen

Page 15: 406 Integrating Swift With Objective c

What Did We Just Do?

Exposed Objective-C to Swift

Page 16: 406 Integrating Swift With Objective c

What Did We Just Do?

Exposed Objective-C to Swift

Defined a protocol in Swift

Page 17: 406 Integrating Swift With Objective c

What Did We Just Do?

Exposed Objective-C to Swift

Defined a protocol in Swift

Exposed Swift to Objective-C

Page 18: 406 Integrating Swift With Objective c

Communication Within a TargetThe bridging header and the generated header

Page 19: 406 Integrating Swift With Objective c

MyApp-Bridging-Header.h

Communication Within a TargetThe bridging header and the generated header

Page 20: 406 Integrating Swift With Objective c

MyApp-Bridging-Header.h

Communication Within a TargetThe bridging header and the generated header

Page 21: 406 Integrating Swift With Objective c

MyApp-Swift.h

MyApp-Bridging-Header.h

Communication Within a TargetThe bridging header and the generated header

Page 22: 406 Integrating Swift With Objective c

MyApp-Swift.h

MyApp-Bridging-Header.h

Communication Within a TargetThe bridging header and the generated header

Page 23: 406 Integrating Swift With Objective c

DemoWorking with frameworks

Jordan Rose

Page 24: 406 Integrating Swift With Objective c

What Did We Just Do?

Added a Swift model object

Page 25: 406 Integrating Swift With Objective c

What Did We Just Do?

Added a Swift model object

Embedded a framework (on iOS!)

Page 26: 406 Integrating Swift With Objective c

What Did We Just Do?

Added a Swift model object

Embedded a framework (on iOS!)

Updated our interface and adopted a delegate protocol

Page 27: 406 Integrating Swift With Objective c

Using Frameworks

Treat user frameworks the same as system frameworks

Page 28: 406 Integrating Swift With Objective c

Using Frameworks

Treat user frameworks the same as system frameworks

Page 29: 406 Integrating Swift With Objective c

Using Frameworks

Treat user frameworks the same as system frameworks

Swift import MyFramework

Page 30: 406 Integrating Swift With Objective c

Using Frameworks

Treat user frameworks the same as system frameworks

Swift import MyFramework

Objective-C @import MyFramework; // Use @import instead of #import

Page 31: 406 Integrating Swift With Objective c

In Conclusion…

Page 32: 406 Integrating Swift With Objective c

Summary

Swift is a better, safer way to do Cocoa development

Page 33: 406 Integrating Swift With Objective c

Summary

Swift is a better, safer way to do Cocoa development

It's still Cocoa!

Page 34: 406 Integrating Swift With Objective c

Summary

Swift is a better, safer way to do Cocoa development

It's still Cocoa!• Some patterns are easier in Swift

Page 35: 406 Integrating Swift With Objective c

Summary

Swift is a better, safer way to do Cocoa development

It's still Cocoa!• Some patterns are easier in Swift

Xcode takes care of the details

Page 36: 406 Integrating Swift With Objective c

More Information

Dave DeLong Developer Tools Evangelist [email protected]

Documentation Using Swift with Cocoa and Objective-C http://developer.apple.com

Apple Developer Forums http://devforums.apple.com

Page 37: 406 Integrating Swift With Objective c

Related Sessions

• Introduction to Swift Presidio Tuesday 2:00PM

• Swift Interoperability In Depth Presidio Wednesday 3:15PM

• Creating Modern Cocoa Apps Marina Thursday 10:15AM

• Building Modern Frameworks Presidio Thursday 3:15PM

Page 38: 406 Integrating Swift With Objective c

Labs

• Swift Lab Tools Lab A Wednesday 9:00AM

• Swift Lab Tools Lab A Wednesday 2:00PM

• Swift Lab Tools Lab A Thursday 9:00AM

• Swift Lab Tools Lab A Thursday 2:00PM

• Swift Lab Tools Lab A Friday 9:00AM

• Swift Lab Tools Lab A Friday 2:00PM

Page 39: 406 Integrating Swift With Objective c