WWDC 2018 What’s new in Cocoa Touch Recap

In What’s new in Cocoa Touch at WWDC 2018, Apple gave an overview of framework updates (largely focused on performance), API enhancements, and Siri shortcuts. You can read my notes from the talk below, and you can watch the video and download the slides from Apple’s WWDC 2018 page.


Overview

  • Framework updates
  • API enhancements
  • Siri shortcuts

Performance updates

  • Scrolling
  • Memory
  • Auto Layout

UITableView, UICollectionView

layoutSubviews and draw can take a lot of time

  • you get 8ms on iPad Pro to do all the work
  • …and 16ms on other devices (due to refresh rate differences)

UITableViewDataSourcePrefetching is a big help most of the time

iOS 12 is more intelligent about background prefetching while scrolling

  • Now iOS passes info about scrolling from UIKit down to lower levels
  • All apps get these enhancements for free

…but to get the most out of the new enhancements:

  • adopt the table view / collection view data source prefetching API
  • profile your app

Memory is Performance

  • The system has to do work to go get memory for you when it’s not available
  • That time could be better spent in your app than in the system

Automatic Backing Store

  • new in iOS 12, default
  • UIView.draw
  • UIGraphicsImageRenderer
  • UIGraphicsImageRendererFormat.Range

Auto Layout

Faster by default in iOS 12

Independent Sibling Views: laid out relative to container, not each other

  • constant cost in iOS 11
  • reduced constant cost in iOS 12

Dependent Sibling Views: layout is dependent on one another

  • Grows exponentially in iOS 11
  • Grows linearly in iOS 12

Nested Views: one view in another, in another, in another

  • Grows exponentially in iOS 11
  • Grows linearly in iOS 12

Swiftification

Automatic migration to new APIs

Nesting types

In Swift 4.2:

UIApplicationState -> UIApplication.State

UITabBarItemPositioning -> UITabBar.ItemPositioning

Nesting constants

NSNotification.Name

UIApplicationStatusBarOrientationUserInfoKey now in UIApplication

UIFloatRangeZero -> UIFloatRange.zero

Nested function

UIEdgeInsetsInsetRect -> rect.insetBy()

UIImagePNGRepresentation -> image.pngImage()

String conversion

Codable conformance for CGPoint, CGRect, CGSize, CGVector…

print(CGPoint(x: 0, y: 0)

NSSecureCoding

New secure-by-default encoding and decoding APIs

Older APIs now deprecated

API Enhancements

Notifications

  • Interaction
  • Grouping
  • Settings

Interaction: Define programmatically

Grouping: iMessage groups all messages from a single conversation

  • you can tag notifications with a thread identifier so they can be grouped

Settings: deep link to your notification settings UI

Messages

Stickers automatically work in Camera

Now you can check whether you’re in Messages or Camera

Automatic Passwords and Security Code AutoFill

iOS 12 lets you store passwords into iCloud Keychain after they log in

You can generate passwords with iCloud Keychain

Make sure auto-generated passwords meet your app’s password requirements

Two-Factor Auth (Security Code) AutoFill

Safe Area

Top & bottom

Different bar heights in split view on iPad

iPhone X gives safe areas in portrait and landscape

Siri Shortcuts

Common actions from your app to Siri

Suggested on lock screen, Siri Watch face

  • NSUserActivity (simpler)
  • Intents (more complex)

NSUserActivity: eligibleForPrediction = true

Intents:

  • Car commands
  • Notes
  • Visual codes
  • Ride booking
  • VoIP calling
  • define your own custom intents

Custom Intents:

  • Do, Run, Go, Create, View, Order, Start…

Shortcuts app: available on the App Store


Hope this helps! If you want more like this, enter your name and email in the boxes below to get all my WWDC 2018 recaps — including the ones for the Keynote and the Platforms State of the Union.