1

I'm developing my first iOS App, using Xcode 11.3 and Swift5.

But I was stuck in using ForEach on view.

I want to put certain struct in ZStack using Foreach but still get errors.

Error : Unable to infer complex closure return type; add explicit type to disambiguate

I don't know how to solve this. Can you help me?

/* Struct I want to put in */
struct Verses: Identifiable{
    var id: Int
    var verse : Int
}
/* I want to load all values from struct using foreach in view. */
        ZStack {
            ForEach(controller.verses) { w in              <- Here is where I get error.

                Rectangle()
                    .foregroundColor(Color.white)
                .cornerRadius(28)
                    .opacity(0.4)
                    .offset(x:0, y:68)
                    .frame(width:290, height:280)

                CardView(date: w.date)
                .gesture(DragGesture()
                .onChanged({ (value) in
......


1
  • Could you put Rectangle and CardView into a another view called Cell. Then use Cell in ForEach Commented Feb 3, 2020 at 4:45

1 Answer 1

2

ForEach row must be represented by single View, so you need something like the following (still I'm not sure in type of container, but just for example)

ForEach(controller.verses) { w in
  ZStack {
    Rectangle()
        .foregroundColor(Color.white)
    .cornerRadius(28)
        .opacity(0.4)
        .offset(x:0, y:68)
        .frame(width:290, height:280)

    CardView(date: w.date)
    .gesture(DragGesture()
    .onChanged({ (value) in

    ...
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.