Posts

Post not yet marked as solved
2 Replies
2k Views
I'm not getting any deprecation warning now when I compile my code with known deprecation. How to enable deprecation warning? I want to get rid of all deprecated calls.
Posted
by mattyoung.
Last updated
.
Post not yet marked as solved
2 Replies
726 Views
Here is my WatchOS app test. I've only tested in the simulator in 11.3.1 (Deployment Target 6.1) and 11.4 beta (Deployment Target 6.2)import SwiftUIprivate final class Foo: ObservableObject { @Published var bar = Color.green}struct FilledButton: ButtonStyle { // this do not work, runtime error when this is referenced, see below, works fine with ViewModifier @EnvironmentObject fileprivate var foo: Foo func makeBody(configuration: Configuration) -> some View { configuration.label .foregroundColor(configuration.isPressed ? .red : .white) .padding() .background(Color.accentColor) .padding() // Thread 1: Fatal error: No ObservableObject of type Foo found. A View.environmentObject(_:) for Foo may be missing as an ancestor of this view. .background(self.foo.bar) // <==== runtime error anytime you reference this .cornerRadius(8) }}struct ContentView: View { var body: some View { AppView() .accentColor(.orange) .buttonStyle(FilledButton()) .environmentObject(Foo()) // <=== @EnvironmentObject is set here, this works with ViewModifier, not ButtonStyle }}struct AppView: View { var body: some View { VStack(spacing: 5) { Text("Hi, I'm Paul!") Keypad() } }}struct Keypad: View { var body: some View { VStack(spacing: 5) { Button(action: {}) { Text("One") } Button(action: {}) { Text("Two") } } }}struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() }}
Posted
by mattyoung.
Last updated
.
Post not yet marked as solved
1 Replies
795 Views
I've created an standalone watch app using SwiftUI. I want a complication that just show the app name. I thought the default should work do this? I've not made any change to the ComplitionController: func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) { // This method will be called once per supported complication, and the results will be cached handler(nil) }I can see my app name in the watch face complication selection list. But it's blank in the watch face itself. Touching it opens my app.What to do?Initially. the complication selection show my app as "MyApp WatchKit App", on the watch face it's blank but touching the complication shows "MyApp WatchKit App" briefly and opens my app. I have no idea where the app name settings is in Xcode. I have set all the "Display Name" fields in Xcode as "MyApp". When I changed the "Identity and Type" field from "MyApp WatchKit App" to "MyApp", the compication configure selection list now show "MyApp". But on the watch face, it's still blank. Toching it shows a square shape, then my app open.
Posted
by mattyoung.
Last updated
.
Post not yet marked as solved
1 Replies
451 Views
When doing SwiftUI, very often you need to wrap a block in another SwiftUI view. Is there a way I can highlight the lines and make it indent one level, and wrap that insdie { }? Like this:line 1line 2line 3to become{ line 1 line 2 line 3}?
Posted
by mattyoung.
Last updated
.