23
Supercharge your Apps with NSOperations by Cocoaheads MTL - March 16th, 2017

Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Supercharge your Apps with NSOperations

by

📍Cocoaheads MTL - March 16th, 2017

Page 2: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

WWDC 2015 Advanced NSOperations

Page 3: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

What we’ll talk about today

• What exactly is an NSOperation?

• What do Operations look like in the real world?

• A whole new world of Operations

page 3/21

Page 4: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Part 1

What’s an NSOperation?

Page 5: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

What’s an NSOperation?

• Wrapper around a block of code

• Run by an NSOperationQueue

• With a bunch of cool features

page 5/21

Page 6: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Cancelable

Page 7: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Dependencies

Page 8: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Multi-Core Aware

Page 9: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Black Box Approach

Page 10: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Part 2

Operations in the Real World

Page 11: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Code that returns right away

• Parsing JSON into a model

• Checking for location permissions

• Saving to NSUserDefaults

page 11/21

Page 12: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Code that returns asynchronously

• Network requests

• Connecting to a Bluetooth device

• CloudKit operations

page 12/21

Page 13: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Code that runs UI

• Showing a UIAlertController

• Presenting complete flows of UI

page 13/21

Page 14: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Part 3

A whole new world

Page 15: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Composable and Reusable

• Small blocks that can be composed and reused

• Because they share the same interface, it’s easy to build components that run on Operations.

page 15/21

Page 16: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

If you can draw a flowchart you can use NSOperations

Page 17: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Some Examples

• Activating Geofence Push Notifications

• Facebook Login

• Parsing Large Datasets

page 16/21

Page 18: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Activating Geofence Push

Page 19: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Activating Geofence Push

Page 20: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Normal Login

Page 21: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Facebook Login

Page 22: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

Parsing Large Datasets

Page 23: Supercharge your Apps with NSOperations · 2017-03-22 · Supercharge your Apps with NSOperations by !Cocoaheads MTL - March 16th, 2017. WWDC 2015 Advanced NSOperations. What we’ll

BONUSES

bit.ly/chmtl2017

Let’s keep in touch 🤝 @Frankacy