Post

Replies

Boosts

Views

Activity

Why does Xcode warn for using ViewBuilder with a return statement?
I'm using @ViewBuilder so I will be allowed to use statements that unwrap values within my views. But I also like to return the body of the view in a return statement, so I can run other code before view code is run. Like this: @ViewBuilder var body: some View { // do some stuff here like set variables differently for iOS and macOS, load different view conditionally based on settings etc… return VStack { // compiler warning: "Application of result builder 'ViewBuilder' disabled by explicit 'return' statement" // etc etc… } } So this builds and appears to work fine, but I get a compiler warning that says "Application of result builder 'ViewBuilder' disabled by explicit 'return' statement" If I apply either of the fixes it suggests, it breaks my code with errors so it can't compile. I don't understand what the problem is. What does it mean that it's "disabled" when its accomplishing my purpose for using @ViewBuilder just fine? Is there a better way to run the code I want to run before the view?
1
0
3.8k
Aug ’22
Adding function parameter to view results in error for existing computed property
I'm trying to pass a function into my view, which also has a calculated property as an init value. Previously, the following code worked fine before attempting to add the function as an init property of my view: var title: String var desc: String { get { return self._desc } set { self._desc = newValue self.suggestions = newValue.components(separatedBy: "\n\n") } } private var _desc: String = "" private var suggestions:[String] = [] public init(title: String, desc: String) { self.title = title self.desc = desc } No Errors—everything works as expected. But then when I add my function to the view and in the init, suddenly it is erroring on the previous line, as if my computed property was the problem: var title: String var desc: String { get { return self._desc } set { self._desc = newValue self.suggestions = newValue.components(separatedBy: "\n\n") } } var action: () -> Void private var _desc: String = "" private var suggestions:[String] = [] public init(title: String, desc: String, action: @escaping () -> Void) { self.title = title self.desc = desc // Errors here: "'self' used before all stored properties are initialized" self.action = action } I've looked at all the posts I can find with this error, but they all deal with circumstances unrelated to what I'm seeing here. Does anyone understand what is happening? Why would adding another parameter to a view trigger this error for a computed property when otherwise it worked fine?
2
0
655
Jul ’22
How to access activity for previous weeks with VoiceOver on in Apple Fitness?
My app has a similar UI to this one in Apple Fitness: I'm trying to figure out how to make my UI fully navigable with VoiceOver on, and the first thing I need to do is understand how users would expect it to operate. So I'm trying to first navigate the same control in Apple's Fitness app with VoiceOver turned on so I can match what they do, and so far I'm stumped. My best guess, based on my limited understanding of how to navigate iOS with VoiceOver, was to flick up and down (the way you do on the paging control on the Home Screen) but that doesn't do it. The other thing I tried was three-finger swiping left and right, but that also does nothing. Can anyone help me understand what the user expectation is for navigating this control with VoiceOver on?
0
0
618
Nov ’21
Why does Xcode warn for using ViewBuilder with a return statement?
I'm using @ViewBuilder so I will be allowed to use statements that unwrap values within my views. But I also like to return the body of the view in a return statement, so I can run other code before view code is run. Like this: @ViewBuilder var body: some View { // do some stuff here like set variables differently for iOS and macOS, load different view conditionally based on settings etc… return VStack { // compiler warning: "Application of result builder 'ViewBuilder' disabled by explicit 'return' statement" // etc etc… } } So this builds and appears to work fine, but I get a compiler warning that says "Application of result builder 'ViewBuilder' disabled by explicit 'return' statement" If I apply either of the fixes it suggests, it breaks my code with errors so it can't compile. I don't understand what the problem is. What does it mean that it's "disabled" when its accomplishing my purpose for using @ViewBuilder just fine? Is there a better way to run the code I want to run before the view?
Replies
1
Boosts
0
Views
3.8k
Activity
Aug ’22
Adding function parameter to view results in error for existing computed property
I'm trying to pass a function into my view, which also has a calculated property as an init value. Previously, the following code worked fine before attempting to add the function as an init property of my view: var title: String var desc: String { get { return self._desc } set { self._desc = newValue self.suggestions = newValue.components(separatedBy: "\n\n") } } private var _desc: String = "" private var suggestions:[String] = [] public init(title: String, desc: String) { self.title = title self.desc = desc } No Errors—everything works as expected. But then when I add my function to the view and in the init, suddenly it is erroring on the previous line, as if my computed property was the problem: var title: String var desc: String { get { return self._desc } set { self._desc = newValue self.suggestions = newValue.components(separatedBy: "\n\n") } } var action: () -> Void private var _desc: String = "" private var suggestions:[String] = [] public init(title: String, desc: String, action: @escaping () -> Void) { self.title = title self.desc = desc // Errors here: "'self' used before all stored properties are initialized" self.action = action } I've looked at all the posts I can find with this error, but they all deal with circumstances unrelated to what I'm seeing here. Does anyone understand what is happening? Why would adding another parameter to a view trigger this error for a computed property when otherwise it worked fine?
Replies
2
Boosts
0
Views
655
Activity
Jul ’22
How to access activity for previous weeks with VoiceOver on in Apple Fitness?
My app has a similar UI to this one in Apple Fitness: I'm trying to figure out how to make my UI fully navigable with VoiceOver on, and the first thing I need to do is understand how users would expect it to operate. So I'm trying to first navigate the same control in Apple's Fitness app with VoiceOver turned on so I can match what they do, and so far I'm stumped. My best guess, based on my limited understanding of how to navigate iOS with VoiceOver, was to flick up and down (the way you do on the paging control on the Home Screen) but that doesn't do it. The other thing I tried was three-finger swiping left and right, but that also does nothing. Can anyone help me understand what the user expectation is for navigating this control with VoiceOver on?
Replies
0
Boosts
0
Views
618
Activity
Nov ’21