Post

Replies

Boosts

Views

Activity

Reply to Corner complication with arching text label
@rolandkajatin How would you handle this in watchOS 9, though? I don't mean, "Can we use it in watchOS 9" - we can't; it's watchOS 10+. I mean, if our Watch app targets watchOS 9, how do you support it for both watchOS 9 and 10? How would this code look? var body: some View { Text("Hi") .widgetCurvesContent() // <-- What do you put here so that this compiles for both 9 & 10? .widgetLabel("World!") }
Topic: App & System Services SubTopic: Core OS Tags:
Sep ’23
Reply to Corner complication with arching text label
Okay, a lot of searching came up with something by Dave DeLong here: https://davedelong.com/blog/2021/10/09/simplifying-backwards-compatibility-in-swift/ public struct Backport<Content> { public let content: Content public init(_ content: Content) { self.content = content } } extension View { var backport: Backport<Self> { Backport(self) } } extension Backport where Content: View { @ViewBuilder func widgetCurvesContent() -> some View { if #available(watchOS 10.0, iOSApplicationExtension 17.0, iOS 17.0, macOSApplicationExtension 14.0, *) { content.widgetCurvesContent() } else { content } } // You can put multiple funcs in here } To use it: ZStack { Text("Hello, world!) .font(.system(size: 21.0, weight: .bold)) } .backport.widgetCurvesContent() .widgetLabel { ... ... etc.
Topic: App & System Services SubTopic: Core OS Tags:
Sep ’23
Reply to Xcode 15 Beta 6 and watchOS beta 5: OS version lower than deployment target
Same issue here. Previews of most complications and Lock Screen circular or rectangular widgets don't work, so I have to rely on the Simulator - and that's an exercise in frustration in itself since Xcode refuses to pair a Watch Simulator with an iOS Simulator properly. I need to deploy to a device to confirm everything works, but I can't. Why do Apple let Xcode out of the building with these showstopper bugs?
Topic: App & System Services SubTopic: Core OS Tags:
Sep ’23
Reply to How to support foregroundColor (deprecated) and foregroundStyle in watchOS 9/10?
Right, it's pretty clear to me now that you cannot use .foregroundStyle(/* any colour */) in a corner complication. myColour is the result of some calculations in a function, but the effect is to return a Color object of .red, .green, or .yellow. In this example it's returning .red. Here's what happens when I use foregroundColor(myColour): .widgetLabel { Text("New York") .foregroundColor(myColour) This works correctly. Now, when I use foregroundStyle(myColour): .widgetLabel { Text("New York") .foregroundStyle(myColour) The text is white, not red. And now, when I use foregroundStyle(.green): .widgetLabel { Text("New York") .foregroundStyle(.green) The text is white, not green. I've tried a simple example in a new project just in a standard view, not in a complication's widgetLabel: Text("Hello, world!") .foregroundStyle(.green) It works fine. It appears that you cannot use .foregroundStyle() on a Text object within a widgetLabel. I've also tried these in a corner complication, just removing the complexity of adding a Text object: // 1 .widgetLabel("Hello, world!") .foregroundStyle(.green) // 2 .widgetLabel("Hello, world!") .foregroundColor(.green) Both of these result in the label being white. So, either I've thoroughly misunderstood this - what should be an incredibly simple thing - or this is a bug. Apple are deprecating foregroundColor() with a broken alternative. Happy to be proven wrong.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’23
Reply to Xcode 15.0 - Failed to Build on Canvas Preview SwiftUI
I get similar errors but I can't really help you with this. My previews do generally work. Sadly, the preview engine in Xcode is terrible anyway. I just spent hours trying to get a circle to render behind some text only to find that it works on the Simulator and a physical device, but not in the Xcode preview. I've now resigned myself to not bothering with the preview at all, given that it's totally different to the actual output. Apple need to spend some time working on this, as it's wasting developers' time.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’23
Reply to Complications not rendering in Watch Series 9
You need to implement .containerBackground() - which is new in watchOS 10. It doesn't work on watchOS 9, so simply adding it will bring compile errors. To get it to work I have a 'backport' extension, as per Dave DeLong's blog here: https://davedelong.com/blog/2021/10/09/simplifying-backwards-compatibility-in-swift/ Here's how to implement it: // MARK: - Backports public struct Backport<Content> { public let content: Content public init(_ content: Content) { self.content = content } } extension View { var backport: Backport<Self> { Backport(self) } } extension Backport where Content: View { @ViewBuilder func containerBackground(_ backgroundView: some View) -> some View { if #available(watchOS 10.0, iOSApplicationExtension 17.0, iOS 17.0, macOSApplicationExtension 14.0, *) { content.containerBackground(for: .widget) { backgroundView } } else { backgroundView } } @ViewBuilder func widgetCurvesContent() -> some View { if #available(watchOS 10.0, iOSApplicationExtension 17.0, iOS 17.0, macOSApplicationExtension 14.0, *) { content.widgetCurvesContent() } else { content } } } I've also added a widgetCurvesContent function so you can see how to use it for other, simpler cases. As the blog says, naming these functions the same as the one they're implementing means it's easy to move forward when you no longer have to support a backport. You would just delete the function from the extension, let Xcode's errors tell you where you were using it, and remove the .backport bit, i.e. .backport.containerBackground(...) -> .containerBackground(...). Now, to use it: .backport.containerBackground( Circle() .fill(.red.gradient) .opacity(0.75) ) Here, you're passing in a Circle object as the backgroundView to the backport.containerBackground function. If you're using watchOS 10 it will apply the containerBackground function with your backgroundView. If you're on watchOS 9 it falls back to just applying the backgroundView. For the simpler case of applying a modifier to something like the text in a corner widget to make it curved, you can use .widgetCurvesContent(). Again, this is only available in watchOS 10+, so you can use the backport function .backport.widgetCurvesContent(). Hope this helps.
Topic: App & System Services SubTopic: Core OS Tags:
Sep ’23
Reply to iOS 17 Companion watch app not installing on device during development
What version of Watch is it, and what version of watchOS is on it? In the bar at the top of the Xcode window (not the menu bar), there's your iOS app target, then the iPhone it's going be deployed to. Click that target dropdown and see if there are any messages next to your Watch. I can deploy to my iPhone 14 Pro Max on iOS 16.4 and an iPhone 15 Pro on iOS 17.0.2, but I can't deploy to my Series 8 Watch 45mm (paired with the iPhone 15 Pro) with watchOS 9.6.2 because Xcode says it has a lower version of watchOS than the target, but the target is watchOS 9.0 so it's a bug in Xcode in my case. Perhaps it's the same for you?
Sep ’23