WWDC21 notes
As last year I decided to share my unedited notes from the sessions I’m watching. The difference is that this time I’ve focued more on the topics and not on the sessions themselves. I’ve found this way more approachable this time.
Note that I haven’t taken many notes about concurrency because is a topic that I’m already well versed since it was avilalbe for months thanks to Swift Evolution. If you want to know my take on that watch my Concurrency talks.
I will keep updating this notes as I watch more sessions.
Updated: 2021-06-09
#if ... #endif
can now surround explicit member expression suffixes. (51690082)- You can now apply property wrappers to function and closure parameters. (SE-0293, 66866426, 78029226)
- Xcode has a new Optimize Object Lifetimes build setting, under Swift Compiler - Code Generation. Enabling this performs more aggressive ARC optimization and shortens object lifetimes, which can help reduce the memory your app uses. This option also helps you find bugs where code makes invalid assumptions about object lifetimes.
- The
lazy
keyword now works in local contexts. (78028578) - Whenever a reference to
Self
doesn’t impede the usage of a protocol as a value type, or a protocol member on a value of protocol type, the same is now true for references to[Self]
and[Key : Self]
. (78028842) - It is now possible to use leading-dot syntax in generic contexts to access static members of protocol extensions where
Self
is constrained to a fully concrete type. (78029041)
Apple Packages:![[apple swift packages.png]]
Static linking on Linux, good for server apps.Better JSON performance on Linux.Better AWS Runtime lambda performance.
Concurrency
- Apple Developer Documentation
- Concurrency in Swift 5 and 6 - Discussion - Swift Forums
- Maybe it will be backwards deployed?!?!?! Swift Concurrency: Feedback Wanted! - #6 by tkremenek - Discussion - Swift Forums
- Integrated with [[#SwiftUI]] callbacks
.task
modifier is a task linked to the view lifecycle.- use for in here and you have a lot of the things you want from Rx/Combine for free!
- but the
refreshable
doesn’t follow the lifecycle. - BUT CANCELLATION DOESN’T SEEM TO BE TIED TO THE LIFETIME!
- SDK changes!:
- UIImage thumbnails
- URLSession
- URL line by line
- FileHandle.bytes
- NotificationCenter
- Core Data
- await context.perform
- but still, that makes it dangerous to return managedObjects.
- MainActor.run {} is useful if you want to group multiple calls to the main actor without suspending (await) in between them.Types of concurrency with tasks.![[Screenshot 2021-06-08 at 18.00.45.png]]
Integrated with XCTest.
SwiftUI
Building a Great Mac App with SwiftUIAdd Rich Graphics to Your SwiftUI App
- TimelineView
- Schedules updates to your view automatically (outside of State changes)
- Periodic
- Explicit
- Animation framerate
- Custom
- AsyncImage AsyncImage | Apple Developer Documentation
- Focus areas,
FocusState
- can be a boolean for 1 case
- or a hashable (enum) to pick which area to focus on
Table
Canvas
Material
- use them as background so the content on top takes the correct vibrancy to be legible.
- Lists:
- swipe actions
- Pull down to refresh Apple Developer Documentation
- Swipe actions Apple Developer Documentation
- separators
- ScrollView.safeAreaInset modifier to keep the scroll inside the safe area but let the content be visible outside the area.
- content is passed in the closure of the modifier.
badge
- .searchable
- is passed trough the environment, if no view does anything with it, defaults kick in
- NavigationView puts the searchbar in the navigation bar
- Environment .isSearching to show results.
- Use an overlay to show the results so the list behind stays there.
- optional viewbuilder closure to offer suggestions
- searchCompletion modifier handles the typical case by converting a non interactive view into a button and changing the searchable text to the suggested.
- use .onSubmit(.search) {} to perform the search when the user submits the search query.
- Landscape previews
- [[#SF Symbols 3]]
- Default set colors
- Accessibilty:
- Rotor:
- header: from Section or with accessibilityAddTrais(.isHeader)
- custom rotors: for example if a visual user can see icon alerting on each cell, a blind user would have to go to each cell to know if there is an alert. instead make a custom rotor that goes trough the alerts only.
.accessibilityRepresentation
use the accessibility representation from one view to define the accessibility of another..accessibilityChildren
modifier to convert a accessibility view into a container with children.- nice trick to use a shapes (rectangle) with accessibility
accessibilityEleemnt(children. contain)
in horizontal carousel of cells, the reading order is top-left -> bottom-right so it would read all top views, then go down to the next element. instead you can mark each “cell” as a container so it reads an entire cell first instead of going to the next. need to understand the id of a view, and use namespace if there is mulitple views with the same id.- `accessibilitySortPriority(-1)`` to read a view last
accessibilityElement(children: .combine)
to make the entire cell 1 single element, keeping the chidlren’s properties.- ![[accessibility child behaviour.png]]
accessibilityFocusState
to control programatically the focus of voiceover
- Rotor:
- better performance on macos
- Debugging helper:
https://twitter.com/luka_bernardi/status/1402045202714435585Call `Self._printChanges()` inside the body of a view to print out the changes that have triggered the view update.
- Text
- now supports Markdown strings.
- with custom attributes in the markdown
- tapable links
- dynamicTypeSizes to restrict the range .
- textSelection modifier to allow it
- date.formatted()
- person.nameComponents.formatted() and support for textField bindings too.
- TextField
- prompt
- onSubmit
- submitLabel
- ToolbarGroup placement: .keyboard
- Button
- .bordered style on iOS!
- .tint
- .controlSize (large gives you the typical full with buttons)
- .controlProminence
- role: .destructive
- Confirmation dialogs
- menuIndicator(.hidden) to make Manu buttons (dropdowns) appear as just a normal button.
- Menu primary action to allow a one click action, with a context menu as a secondary action.
- Toggle .button style to make a button that toggles.
- ControlGroup groups related controls.
- Core Data fetch request property wrapper now gives binding to sort propery.
- Core Data sectioned fetch request.
- importItemProviders modifier to accept data from other apps.
- exportItemProviders modifier to share data from your app. Nice to integrate it with shortcuts!
- Mac: ImportFromDevicesCommands() as commands in the window group to add functionity to get images from an iPhone.
- privateSensitive to redact UI when in private modes like watch always on mode, or widgets on the lock screen.
- Accessibility modifiers visible in the Xcode inspector.
- Accessibility preview tab.
Thanks to property wrappers in function parameters we can pass a binding to an array in List and ForEach.
Widgets
New extra large size for iPad.Donate to the system so it can show the widget to the user on smart rotating stacks:
- INRelevantShortcut, from the app, to suggest a widget
- TimelineEntryRelevante, from widget extension, to rotate
- INInteraction, from the app, to suggest and rotate
SharePlay, GroupActivities Framework
Activities.CoreMedia + Group Activities coordinate the video playback across all devices. It plays locally on your app on everybody’s device.Based on URLs/Deeplinks.Reliable Data channel, e2e encrypted. For any kind of experience, realtime.
iPad Swift Playgrounds
…
UIKit
- UISheetPresentationController Apple Developer DocumentationUITooltips
- keyboard layout guide Apple Developer DocumentationUIImage resizing thumbnail creation.
- bars are now transparent. if is not appropiate make a custom barappearance.
- vc.setcontentscrollviewforedge lets you tell uikit which scroll to handle.
- New UIList
- lists styles: prominentInsetGrouped and extraProminentInsetGrouped for lists with rich content so headers are not lost.
- separator configuration
- DatePicker wheel is back, but can type on the dates.
- Button
- New configuration API
- popup and pulldown menu buttons
- Button now supports multiple lines of text.
- subtitle configuration property.
- setNeedsUpdateConfiguration with the configuration closure to update the button. button own properties (highlight) will call the closure automatically.
- incorporated activity indicator!
- toggle buttons that keep the selected state.
changesSelectionAsPrimaryAction = true
- pop-up buttons (similar to pull-down buttons with
showMenuAsPrimaryAction
) but with only 1 selection. works via menus by addingchangesSelectionAsPrimaryAction
. pre assign the default by settingstate: .on
in theUIAction
.
- cells and buttons configuration can be applied with a closure based api. no need to subclass cells anymore.
- [[#SF Symbols 3]]
- restrict dynamic type sizes.
- system colors are the same on all platforms.
CoreLocationUI
- Scenes:
- saving state by giving a user activity to persist
- and with a new delegate method to restore.
- can request some extended time to perform async restoration. but don’t use this for long tasks like api requests!
- textField and textView have a
interactionState
property that gives you the restoration state of the field, but not the text content. - uiscene “share this” api
- iPad center prominent scene like mail.
- ActivationAction to put on menus and AcitvationInteraction to put on cells or views do use the gesture.
- customise the preview by giving it a view
- use QLPreviewSceneActivationConfiguration to use a system provided preview scene.
- iPad Keyboard support has many improvements for menu and shortcuts.
- automatic localisation for shortcuts
- iPad: uibandselectioninteraction (drag a rectangle to select multiple things). automatic support on non-list collection views.
- iPad pointer:
- accessory vies that follow the pointer.
- latching axis so the pointer stays transformed when the view is moving.
- UIFocus system across all platforms.
- reconfigure cells without recreating them
https://twitter.com/smileyborg/status/1402056034416398338 Do you use diffable data source?
If so, there are some big changes in iOS 15:
- applySnapshot(_: animatingDifferences: false) now diffs & only performs minimal updates to UI
- New API applySnapshotUsingReloadData if you want reloadData
- New API to efficiently reconfigure items!Generally speaking, you should continue to use applySnapshot() — whether animating or not — whenever possible, and avoid using reloadData (as that’s a big hammer that resets everything, it throws away all your existing cells and more).But there are some cases where reloadData does make sense, e.g. if you are applying a completely different set of data, or recycle the collection/table view for use on an entirely different screen, or have a huge set of changes and want to skip diffing/updates.You might find that this behavior change for animatingDifferences:false exposes some issues.The simple quick fix to get the old behavior back is just to use applySnapshotUsingReloadData instead of animatingDifferences:false.But, be aware that may just paper over real bugs.@jesse_squires Before iOS 15:animatingDifferences:true –> diff + updates (animate)animatingDifferences:false –> reloadDataiOS 15:animatingDifferences:true –> diff + updates (animate)animatingDifferences:false –> diff + updates (no animation)applySnapshotUsingReloadData –> reloadData
- collectionview prefetch changes?
- drag and drop across apps works on iphone.
- Location button
- doesn’t ask permission, is a one time only thing
- customise look
- ios ensures is always visible and can be used to trick the user
- The pasterboard banner won’t appear if it comes from a user command or if they come from standard paste acitons: paste, paste and go, paste and search, paste and match style.
- pasteboard data detectors.
- don’t gran access to the data but tell you if it could be a type of data you are interested in.
Xcode
PR comments inline the code.Vim modeRun tests repeatedly to find issues.Better diff and code reviewCrashlogs into the Organiser in minutes, with user comments in crash reports.Cloud signing based on keys stored in connect.Editing:
- Auto import frameworks as needed
- if let name = name auto completed.
- suggestions go inside intermetiate objects.
text.corn
->text.layer.cornerRadius
- switch cases autocompletion without having to click on the fix it.
- for X in array automaitcally gives a singlar name to X based on the array.
- expansion of multiple closures follows the nice new syntax.Column breakpoints, nice to stop only inside a closure.
With package collections Xcode can find modules you want to important and show them so you are one click away.
Alternate app icons in the asset catalog.You can now use platform filters in build phases and target dependencies for all supported platforms.
Instruments
- Analyse network traffic
DocC
Build, view and share documentation for Swift packages using DocC.Documenting a Swift Framework or Package | Apple Developer DocumentationThe documentation works in Xcode doc viewer and as a web page.Add extra pages like index, articles and even tutorials.Xcode’s Quick Help now uses DocC to present project documentation and renders links to your project’s documentation in the documentation windowOpen sourced later this year.
Xcode cloud
For all Apple platforms.Paralleized testingStatic analysisBuild results and screenshoots in Xcode and App Store Connect.Auto deploy to testlfihgREST apis.Code signing automatically handledssxx.Needs changes to support Cocoapods, a build script. Seems like there is no way to customise the execution, it only runs Xcode stuff. But if you have them in Git is fine. Apple Developer Documentation
iOS
iOS 15 doesn’t drop any device! https://twitter.com/JoshHrach/status/1401986459645530114
JSON5 supported, so Comments in JSON!
Foundation
-Attributed String value type to Apple Developer Documentation- with Markdown support!- full Swift, doesn’t rely on NSAttributedString https://twitter.com/jmschonfeld/status/1402038729850585090- supports attributes and even user defined ones Apple Developer Documentation- compatible with Swift String counting- fully localizable- AttributeContainer to hold attributes without the string- Scopes to securely define what attributes are accepted.
- New formatting API!
- extensions on Date, Numbers…
- so no more worry about creating custom formatters and cashing them!
- get an attributed string so you can customise parts of it!
- the same formats are strategies to parse dates. custom strategies use string interpolation
- Morphology
- System wide user’s pronoun.
- Grammer engine to Expand loaclisation with plurals, gender, et
- JSON 5 support
- comments
Notifications
Focus Notifications different alert levels:
- passive: silent, don’t awake the device.
- active
- time sensitive: skips the summary, stay a bit longer, siri speaks it out loud on headphones
- critical: health concerns, requires entitlement.
- message / callNotification summary:
- what shows up is based on relevancy, thumbnail size, amount of notifications… but untimely is user customized.
SF Symbols 3
SF Symbols - Apple Developer600+ new symbolsnew color rendering modesworkflow optimisationcustom symbol improvementsmore localisation options
- variants (fill) will automatically be picked by swiftui (tabs filled on iOS but outlined on macOS)
- hierarchical: monocrhome but with multiple levels of opacity
- palette: customise the colors of each layerpick styles programatically
WatchKit
MailKit
TextKit 2
TextKit 1 it’s there since the NextStep days.TextKit 2 still leverages Foundation, Quartz and CoreText.
- Correctness: abstract away glyph handling. Necessary for international text.
- Safety: value semantics (immutable classes)
- Element: paragraph, attachment, custom!
- Performance: viewport-based layout and rendering
- Non contiguous text layout. More performant for large documents.
ShazamKit
ShazamKit
Audio recognition for our Apps, not only Music. Matches audio to an existing catalog.Is not Sound Analysis classification, use ML for that.
- Shazam catalog recognition: for song identification.
- Custom catalog recognition: device matching of arbitrary audio.
- Library management
HealthKit
- Move minutes
- Alcohol consumption (number of drinks)
- Pregnancy tests
- Walking steadiness
AR
Creating 3D Objects from Photographs
Metal
…
Game
New game controller HUD
Screen Time API
100% Swift and SwiftUI code.Parent control apps: needs Family Control capability. Only works on a child’s device.
- Managed settings: access to the same restriction that Screen Time has.
- restriction of apps, custom branding screen when locked.
- limit access and provided custom actions.
- Family controls: authorization.
- allow parents to chose the apps for the kids
- the app doesn’t get the bundle IDs, just tokens, so only the parents know which apps are
- Device activity: usage.
- with the tokens from the family controls.
- register time windows and completion events so your app can react, sending alerts or blocking apps.
- system calls your extension.
Shortcuts
On mac. Imports Automator flows. Supports shell scripts and applescript.Uses siri intents like in iOS.Exposes a CLI and scripting interface, with ScriptingBridge framework you can run shortcuts from an app.Sharable via files.
![[types-nouns-actions-verbs-intents.png]]
Intents should be:
- Useful
- Handles a task
- Not too immersive
- Repeatable
- Modular
- Composable
- Useful standalone
- Customizable with parameters
- Offer outputs so shortcuts can be build
- Useful ones: Create, edit, delete, get, pick a thing, open app
- Multimodal:
- Compatible with UI and Siri
- Configurable in editor
- Visually represented in snippets (siri UI)
- Clear (in the editor)
- summarised in a sentence
- consistent between suummary and title
- include default values
- Discoverable
- icloud links
- add to siri
App Store / StoreKit
StoreKit 2 introduces a modern Swift-based API that takes advantage of new language features like Swift concurrency. Use this API to load product information, display in-app purchases in your store, allow customers to make purchases, manage access to content and subscriptions, and receive transaction information signed by the App Store in JSON Web Signature (JWS) format
Other
Human Interface Guidelines with Inclusion in mind Inclusion - Technologies - Human Interface Guidelines - Apple Developer