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      

Hacking with Swift is sponsored by Superwall

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.