uri nachmias - adopting swift @houzz - the good, the bad and the ugly

64
How we adopted Swift at Uri Nachmias - iOS developer or [email protected]

Upload: tlv-ios-dev

Post on 19-Aug-2015

95 views

Category:

Mobile


1 download

TRANSCRIPT

How we adopted Swiftat

Uri Nachmias - iOS developer

or

[email protected]

GoalsUnderstand Swift better

The challenges we faced at Houzz

8 features of Swift(good bad and ugly)

Beginner’s guide

GoalsUnderstand Swift betterThe challenges we faced at Houzz

8 features of Swift(good bad and ugly)

Beginner’s guide

Understand Swift better

Let’s go back

Why fear Swift?

Why fear Swift?People fear change

Forget everything you believe in

It just (doesn’t) workCan’t teach old dog new tricks

Everyone is already doing it

Why should I startwriting code in Swift?

Why should I start writing code in Swift?

* Because Apple said so* Swift is cool* Swift has a lot of benefits* Now easier with Swift 2.0

Excuses

* ObjC still works* Swift will probably change a million more times.* Can’t release a Swift 2.0 app until iOS 9.* I like my []

GoalsUnderstand Swift betterThe challenges we faced at Houzz

8 features of Swift(good bad and ugly)

Beginner’s guide

GoalsUnderstand Swift better

The challenges we faced at Houzz8 features of Swift

(good bad and ugly)

Beginner’s guide

The app.Millions of users

The app.Millions of users

The app.What does Houzz do?

Browse photos

The app.What does Houzz do?

Detailed info

The app.What does Houzz do?

Filter through

The app.What does Houzz do?

Find products

The app.What does Houzz do?

Find professionals

The app.What does Houzz do?

Personal professional pages

The app.What does Houzz do?

Newspaper stories

The app.What does Houzz do?

User advice forums

The app.What does Houzz do?

Personalized ideabooks

The app.What does Houzz do?

Shopping cart with Apple Pay support

The app.What does Houzz do?

Shopping cart with Apple Pay support

The app.What does Houzz do?

Shopping cart with Apple Pay support

The app.What does Houzz do?

Share extension Today extension

4 targetsCore frameworkToday extensionShare extension3rd party libs

The app.

The app.

Where did I start?Why did I start?

Today view controller:Table view cell

The app.

Today view controller:Table view cell

The app.

Share extension:Mostly SwiftComplex logic.

Today view controller:

Table view cell

The app.

Share extension:

Mostly SwiftComplex logic.

Cool stuff

Today view controller:

Table view cell

The app.

Share extension:

Mostly SwiftComplex logic.

Pyramid of doom

Today view controller:

Table view cell

The app.

Share extension:

Mostly SwiftComplex logic.

Cool switchcases

Today view controller:

Table view cell

The app.

Share extension:

Mostly SwiftComplex logic.

Hard times:

The app.Code structure

~1300 objective c classes~100 Swift classes

Tons of customization

Tons of swizzling and class injection

(auto resizing table views, custom constraints, graphic effect, HTML text labels, auto serializing objects etc..

etc.. etc..

(Auto releasing blocked base KVO, iOS 7 based collection traits and user activities…)

Localized to 15 languages.Some code dates back to 2009

GoalsUnderstand Swift better

The challenges we faced at Houzz8 features of Swift

(good bad and ugly)

Beginner’s guide

GoalsUnderstand Swift better

The challenges we faced at Houzz

8 features of Swift(good bad and ugly)

Beginner’s guide

8 features of Swift1. Variable willSet and didSet and lazy

8 features of Swift1. Variable willSet and didSet and lazy

DEMO

1. Variable willSet and didSet and lazyAwesome replacement for custom getters and setters or internal KVO

Makes Swift safer

Great trick for thinning viewDidLoad(nice side effect - helps avoid nil outlets)not called during init / deinit

GOOD:

BAD:

no built in replacement for atomic.UGLY:

8 features of Swift

2. Optionals8 features of Swift

2. Optionals8 features of Swift

Optionals express nullability(no difference between primitives and objects)

2. Optionals8 features of Swift

DEMO

2. Optionals

Great way to express nullabilityAwesome for searches.

You need to get the hang of it.

GOOD:

BAD: Welcome to a new world of runtime errors.

UGLY:Don’t just add ! or ? or ?! and wait for it to compile

8 features of Swift

3. Slow or fast?8 features of Swift

3. Slow or fast?

Great way to get reacquainted with your Facebook friends.

Getting the error message at the end of the compilation

GOOD:

BAD: Debug code can fool you.

UGLY:

Runtime code can be fastMake sure you test in release modeMake sure you play nice; final, let/var, privates, minimize bridging, bitcode, whole module optimization etc…

8 features of Swift

4. Debugger8 features of Swift

4. Debugger

Playgrounds probably work betterGOOD:BAD: It just (doesn’t) work

8 features of Swift

5. Structs and protocols8 features of Swift

5. Structs and protocols8 features of Swift

New building blocks of Swift code.

No (or limited) ObjC support

GOOD:

BAD: Can be confusing when to use a class and when to use a struct

UGLY:

Can do almost anything a class doesValue semanticsCan be put directly in any collection typeProtocol Oriented Programming

6. Localizations

(known issue)

8 features of Swift

Genstrings bug

7. Type accuracy8 features of Swift

7. Type accuracy8 features of Swift

DEMO

7. Type accuracy

Safer code

Can be cumbersome

GOOD:

BAD:Error messages.UGLY:

Much better with Swift 2.0

8 features of Swift

8. @availableIn Houzz we swizzle and inject a lot

Swift 2.0 availability forbids itrespondsToSelector is not safe

Workaround - put in the bridging header

8 features of Swift

GoalsUnderstand Swift better

The challenges we faced at Houzz

8 features of Swift(good bad and ugly)

Beginner’s guide

GoalsUnderstand Swift better

The challenges we faced at Houzz

8 features of Swift(good bad and ugly)

Beginner’s guide

Where do I start ?WWDC 2014* Beginner Swift* Intermediate Swift* Swift - ObjC interoperabilityThen go and write some Swift codeWWDC 2015* What’s new in Swift* Protocol oriented programming in SwiftThen go and write some Swift code

Beginner’s guide

GoalsUnderstand Swift better

The challenges we faced at Houzz

8 features of Swift(good bad and ugly)

Beginner’s guide

GoalsUnderstand Swift better

The challenges we faced at Houzz

8 features of Swift(good bad and ugly)

Beginner’s guide