UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SwiftUI view as complication

Forums > watchOS

Hi guys!

Me again and I’m wondering if there’s anyone out there who’s played with WatchKit and using SwiftUI views as complications. Going through wwdc20 vids atm but would love a tutorial or something so I can make sense of it all.

I'm closer now I think,

Ive created the descriptors for the complication view here:

func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) {
        var descriptors : [CLKComplicationDescriptor] = []
        descriptors.append(CLKComplicationDescriptor(identifier: "ComplicationView",
                                                     displayName: "Complication View",
                                                     supportedFamilies: [.circularSmall]))
        // Call the handler with the supported complication descriptors
        handler(descriptors)
    }

And now I have to create the template and I know this is wrong, but would love some pointers for some help. Thanks

func createTemplate(
        forComplication complication: CLKComplication,
        date: Date) -> CLKComplicationTemplate? {
        let defaultTemplate: (CLKComplicationFamily) -> CLKComplicationTemplate = { family -> CLKComplicationTemplate in
              // Return a default complication template for the given family
            }
        switch (complication.family, complication.identifier) {
            case (.circularSmall, "ComplicationView"):
                return CLKComplicationTemplateGraphicCircularView(ComplicationView())
        }

Thanks Mark

5      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.