using swift enums for safer uicollectionviews and uitableviews

21
Using Swift Enums for safer UICollectionViews and UITableViews swift.berlin meetup November 30, 2015 Ariel Elkin

Upload: ariel-elkin

Post on 22-Jan-2018

267 views

Category:

Technology


2 download

TRANSCRIPT

Using Swift Enums

for safer UICollectionViews

and UITableViews

swift.berlin meetup November 30, 2015

Ariel Elkin

PROJECT A

• Early-stage investor and company builder • Marketplaces, E-commerce, Saas • 20+ companies in our portfolio

ME

• iOS Developer in Project A’s Mobile Team • 10+ apps in the App Store • Puts his dishes in the dishwasher

COLLECTION VIEWS ARE COMPLEX

• section numbers

• item sizes

• section count

• reuse identifiers

• etc…

MANAGING THE LAYOUT STRUCTURE

• Typically involves hard-coding integer values

MANAGING THE LAYOUT STRUCTURE

• Layout information is fragmented

DISADVANTAGES

MANAGING THE LAYOUT STRUCTURE

• We have to manually ensure that checks are exhaustive

DISADVANTAGES

MANAGING THE LAYOUT STRUCTURE

• Error handling not included

DISADVANTAGES

THE LAYOUT STRUCTURE?

HOW CAN THE COMPILER HELP US WITH

ENUMS

ENUMS

• turn the layout structure into a type

NATURAL ERROR-HANDLING

ENUMS

EXHAUSTIVITY

ENUMS

EXHAUSTIVITY

ENUMS

ENUM FUNCTIONS AND PROPERTIES

ENUMS

COUNT

ENUMS

AUTOCOMPLETION GOODNESS

ENUMS

DEMO

FAVOUR DECOUPLING

ENUMS

THANK YOU!

QUESTIONS?