watchOS: Complications

Feb 7 2023 · Swift 5.6, watchOS 8.5, Xcode 13

Part 1: Introduction to Complications

02. Create Your First Complication

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 01. Explore Complications Next episode: 03. Update a Complication's Data

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Explore the sample

To start, we’ll build a complication for this TideWatch app, so let’s see what we’ve got to work with.

Complication data source

When you create a watchOS project, Xcode will generate ComplicationController.swift. For the sample project, I’ve moved it into the Complications folder, here.

The current timeline entry

When watchOS wants to update the data displayed for your complication, it calls this method. You’re expected to return either the data to display right now or nil if you can’t provide any data.

guard complication.family == .graphicCircular else {
  return nil
}
let template = CLKComplicationTemplateGraphicCircularStackText(
  line1TextProvider: .init(format: "Surf's"),
  line2TextProvider: .init(format: "Up!")
)
return .init(date: Date(), complicationTemplate: template)
func complicationDescriptors() async -> [CLKComplicationDescriptor] {

}
  [
    .init(
      identifier: ~,
      displayName: ~,
      supportedFamilies: ~
    )
  ]
}
identifier: "com.yourcompany.TideWatch",
displayName: "Tide Conditions",
supportedFamilies: [.graphicCircular]