Questions tagged [viewbuilder]

54 questions
0
votes
1 answer

SwiftUI ViewBuilder: is it guaranteed that in `if/ese` statement `else` clause isn't executed when condition is true?

I ask this because I suddenly realized today that, since the if/else statement we use to build View in SwiftUI is interpreted by ViewBuilder, it may behave differently than the plain old if/else statement in Swift language. Could it be that, for…
rayx
  • 1,329
  • 10
  • 23
0
votes
1 answer

Swiftui pass viewbuilder to parent view

I'm building a view router that switch views based on "currentPage" stored in the model. struct RouterView: View { @EnvironmentObject var routerViewModel: RouterViewModel var body: some View { if routerViewModel.currentPage == .login { …
filip.karas
  • 596
  • 2
  • 11
  • 27
0
votes
1 answer

Cannot convert value of type 'TupleView<(Text, Text)>' to closure result type 'Text'

I am trying to understand why I keep getting an error when I try to use this custom layout view I've created. Here is the error (also commented in the code below): Cannot convert value of type 'TupleView<(Text, Text)>' to closure result type…
ra9r
  • 4,528
  • 4
  • 42
  • 52
0
votes
1 answer

SwiftUI ViewBuilder can't pass in different views

In Swift/SwiftUI, I'm trying to make a custom view, which takes other views as arguments. However, I'm getting the error Type of expression is ambiguous without more context. I know that this error is usually due to mismatching types. Also, in the…
Stoic
  • 945
  • 12
  • 22
0
votes
0 answers

SwiftUI Control Flow and ViewBuilder

I want to have a mother view that displays a different child view based on a @State bool. However I get two errors when doing that. On the start of the body closure: Struct 'ViewBuilder' requires that 'EmptyCommands' conform to 'View' Return type…
0
votes
1 answer

SwiftUI: Generic parameter 'Value' could not be inferred

Following codes gives an error of "Generic parameter 'Value' could not be inferred". Appreciate anyone could point out the root cause and let me know how to fix it. Thanks import SwiftUI private let readMe = """ This case study demonstrates how…
LiangWang
  • 8,038
  • 8
  • 41
  • 54
0
votes
1 answer

How can I mimic the calling signature of NavigationLink

I have code like this: List(datalist) { data in     NavigationLink(destination: View1(data: data).headless()) {                  Text(data.name)         }     } where headless() is a way to avoid all the default top views of a…
MarkAurelius
  • 1,203
  • 1
  • 14
  • 27
0
votes
1 answer

Using Variables in Viewbuilder (Swift)

I'm new to swift and Viewbuilder and I am trying to use variables in the Viewbuilder correctly. The objective of this code is to reveal the answer to a question using an animation. The question is presented on a card and when the button on the card…
Mxyb
  • 83
  • 1
  • 9
0
votes
1 answer

Saving ViewBuilder parameters to be used outside of init

I'm creating a custom object called AsyncImageCached using the same init signature as found in AsyncImage. My question is, how do I define variables outside of init to save content and placeholder parameters to be used when my async await calls…
J. Edgell
  • 1,555
  • 3
  • 16
  • 24
0
votes
1 answer

Passing a String value to a viewbuilder from another view

This is the Base View struct BaseView: View { @State private var ShowSFView : Bool = false let content: Content init(@ViewBuilder content: () -> Content ) { self.content = content() …
Ae Ri
  • 185
  • 1
  • 12
0
votes
1 answer

Custom Rating view with nested H and VStacks leads to weird frame

I'm trying to clone this view: Unfortunately I have a problem with the Geometry Reader (I guess). It's making a bigger frame then the actual rectangle (see blue area): Same applies to the stars as well: Can you point me to my issue? Is something…
SwiftUIRookie
  • 591
  • 7
  • 16
0
votes
1 answer

Build Recursive Text View in SwiftUI

My goal is to create a SwiftUI view that takes a String and automatically formats that text into Text views. The portion of the string that needs formatting is found using regex and then returned as a Range. This can be used to…
imattice
  • 152
  • 1
  • 9
0
votes
0 answers

Variable is NIL when it shouldn't be

I probably worked too much today.. In this tiny app when the button is clicked a new view must appear after 3 seconds hVideoURL variable is assigned a value (which is not NIL). So a new view (sheet) should appear with the text "IS NOT NIL".. But for…
eugene_prg
  • 948
  • 2
  • 12
  • 25
0
votes
1 answer

How do I initialize a Bool in this SwiftUI @ViewBuilder based on an optional Binding?

My goal here is to use a ternary operator to add a shadow to my Image, but not add one if the View is using the default image. This is my code: import SwiftUI struct ImageDisplay: View { @State private var defaultImage: Image =…
Rillieux
  • 587
  • 9
  • 23
0
votes
0 answers

ViewBuilder not building, functionality not working

Getting an error: Cannot convert value of type '_ConditionalContent' to specified type (). This seems like an error with the latest update.. however I have other ViewBuilders in my code that I am afraid to touch now. I honestly can't…
Sergio Bost
  • 2,591
  • 2
  • 11
  • 29