UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: XCode13 - Duplicated UI elements (DAY-65)

Forums > 100 Days of SwiftUI

Hi all. I getting a weird behaviour in XCode13. I am going through the 100 days of SwiftUI and day 65 (Instafilter app), I am not able to see the UI in canvas (more then 5 secondds error) and in my phone I get all the items duplicated and app crash because of memory. I just coded the first video of day-65.

Thanks, Renato.

3      

Chances are you typed something wrong and it's causing Xcode to choke. Please post your code.

3      

Thanks @roosterboy! Here is the code. I think the problem is in the ZStack with the rectangle(). If I remove that block of code it works.

import SwiftUI

struct ContentView: View {

    @State private var image: Image?
    @State private var filterIntensity = 0.5

    var body: some View {
        NavigationView {
            VStack {
                HStack {
                    Rectangle()
                        .fill(Color.secondary)

                    if image != nil {
                        image?
                            .resizable()
                            .scaledToFit()
                    } else {
                        Text("Tap to select picture")
                            .foregroundColor(.white)
                            .font(.headline)
                    }
               }
                onTapGesture {
                    //select an image
                }

                HStack {
                    Text("Intensity")
                    Slider(value: self.$filterIntensity)
                }
                .padding(.vertical)

                HStack {
                    Button("Change Filter") {
                        //change filter
                    }

                    Spacer()

                    Button("Save") {
                        //save the picture
                    }
                }
            }
            .padding([.horizontal, .bottom])
            .navigationBarTitle("Instafilter")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

3      

Found the problem...missing . in the .onTapGesture. Thanks!

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.