View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vídeos

Abrir menu Fechar menu
  • Coleções
  • Todos os vídeos
  • Sobre

Mais vídeos

  • Sobre
  • Código
  • Create complications for Apple Watch

    When you add complications to a Watch app, people can access glanceable and up to date information directly from their watch face. We'll show you how to create and build complications from the ground up and introduce you to Multiple Complications. Learn how to construct timelines, use families and templates, and discover best practices on crafting a thorough complication experience.

    Recursos

    • Creating and updating a complication’s timeline
    • ClockKit
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    WWDC20

    • Build complications in SwiftUI
    • Keep your complications up to date
    • Meet Watch Face Sharing
  • Buscar neste vídeo...
    • 4:54 - CLKComplicationDataSource - Required Methods

      // CLKComplicationDataSource - Required
      class ComplicationController: NSObject, CLKComplicationDataSource {
      
          func getCurrentTimelineEntry(
              for complication: CLKComplication, 
              withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void)     
          {
              // Call the handler with the current timeline entry
              handler(createTimelineEntry(forComplication: complication, date: Date()))
          }
      }
    • 5:16 - CLKComplicationDataSource - Timeline Support

      // CLKComplicationDataSource - Timeline Support
      extension ComplicationController {
      
          func getTimelineEndDate(
              for complication: CLKComplication, 
              withHandler handler: @escaping (Date?) -> Void) 
          {
              handler(timeline(for: complication)?.endDate)
          }
      
          func getTimelineEntries(
              for complication: CLKComplication, 
              after date: Date, 
              limit: Int, 
              withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) 
          {
             handler(timeline(for: complication)?.entries(after: date, limit: limit))
          }
      }
    • 8:11 - CLKDateTextProvider initialization

      let longDate: Date = DateComponents(year: 2020, month: 9, day: 23).date ?? Date()
      let units: NSCalendar.Unit = [.weekday, .month, .day]
      let textProvider = CLKDateTextProvider(date: longDate, units: units)
    • 8:49 - CLKRelativeDateTextProvider initialization

      let timerStart: Date = …
      let units: NSCalendar.Unit = [.hour, .minute, .second]
      let textProvider = CLKRelativeDateTextProvider(date: timerStart, style: .timer, units: units)
    • 13:16 - CLKComplicationDataSource - Multiple Complication Support

      // CLKComplicationDataSource - Multiple Complication Support
      extension ComplicationController {
          var descriptors : [CLKComplicationDescriptor] = []
          var dataDict = Dictionary<AnyHashable, Any>()
              
          for station in data.stations {
              dataDict = [“name": station.name, “shortName": station.shortName]
              descriptors.append(
                  CLKComplicationDescriptor(
                      identifier: station.name,
                      displayName: station.name,
                      supportedFamilies: CLKComplicationFamily.allCases,
                      userInfo: dataDict))
          }
          
          descriptors.append(
              CLKComplicationDescriptor(
                  identifier: "LogSighting",
                  displayName: "Log Sighting",
                  supportedFamilies: CLKComplicationFamily.allCases))
      
          descriptors.append(
              CLKComplicationDescriptor(
                  identifier: "SeasonData",
                  displayName: "Season Data",
                  supportedFamilies: [.graphicRectangular]))
              
          // Call the handler with the currently supported complication descriptors
          handler(descriptors)
      }
    • 17:09 - CLKComplicationDataSource - Sample Templates

      func getLocalizableSampleTemplate(
          for complication: CLKComplication, 
          withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) 
      {
          let template = createSampleTemplate(forComplication: complication)
          handler(template)
      }
    • 17:33 - Whale Watch - Entries

      func createTimelineEntry(
          forComplication complication: CLKComplication, 
          date: Date) -> CLKComplicationTimelineEntry? 
      {
          guard let template = createTemplate(forComplication: complication, date: date) else {
              return nil
          }
          return CLKComplicationTimelineEntry(date: date, complicationTemplate: template)
      }
    • 17:44 - Whale Watch - Templates

      func createTemplate(
          forComplication complication: CLKComplication, 
          date: Date) -> CLKComplicationTemplate? 
      {
          var station: Station? = nil
          if let stationName = complication.userInfo?["name"] as? String {
              station = data.stations.first(where: { $0.name == stationName })
          }
          
          let image = UIImage(named: "Spout-small")!
          let spoutFullColorImageProvider = CLKFullColorImageProvider(fullColorImage: image)
          let logSightingTextProvider = CLKSimpleTextProvider(
              text: "Log Sighting", 
              shortText: "Log")
      
          let defaultTemplate: (CLKComplicationFamily) -> CLKComplicationTemplate = { family -> CLKComplicationTemplate in
            // Return a default complication template for the given family
          }
        
          switch (complication.family, complication.identifier) {
      
          case (.graphicRectangular, "SeasonData"):
              return CLKComplicationTemplateGraphicRectangularFullView(
                  ChartView(
                      seriesData: data.last7DaysSightings, 
                      seriesColor: .turquoise)
      
          case (.graphicCircular, "LogSighting"):
              return CLKComplicationTemplateGraphicCircularStackImage(
                  line1ImageProvider: spoutFullColorImageProvider, 
                  line2TextProvider: logSightingTextProvider)
      
          case (.graphicCircular, _):
              guard let station = station else { return defaultTemplate(.graphicCircular) }
              return CLKComplicationTemplateGraphicCircularView(
                  SightingTypeView(station: station))
                
          case (.graphicCorner, _):
              guard let station = station else { return defaultTemplate(.graphicCorner) }
              return CLKComplicationTemplateGraphicCornerTextImage(
                  textProvider: station.timeAndShortLocTextProvider, 
                  imageProvider: station.whaleActivityFullColorProvider)
                      
          case (.graphicExtraLarge, _):
              guard let station = station else { return defaultTemplate(.graphicExtraLarge) }
              return CLKComplicationTemplateGraphicExtraLargeCircularStackText(
                  line1TextProvider: station.timeAndLocationTextProvider, 
                  line2TextProvider: station.shortLocationTextProvider)
      
          default:
              return defaultTemplate(complication.family)
          }
      }

Developer Footer

  • Vídeos
  • WWDC20
  • Create complications for Apple Watch
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines