ios – Faucet wherever so as to add a number of objects on canvas


You solely have a singular location, so just one merchandise will ever seem in your instance. To have a number of objects, you will want some kind of assortment, like an Array.

The next is a pared-down instance exhibiting utilizing an array:

struct Hammer: Identifiable {
    var id = UUID()
    var location: CGPoint

struct Level1: View {
    @State var hammers: [Hammer] = [] //<-- Begin with `none`
    var physique: some View {
        ZStack {
            ForEach(hammers) { hammer in // Show the entire hammers
                Picture(systemName: "hammer.fill")
                    .body(width: 30, top: 30)
        .body(maxWidth: .infinity, maxHeight: .infinity)
        .gesture(DragGesture(minimumDistance: 0).onEnded { worth in
            self.hammers.append(Hammer(location: worth.location)) // Add a Hammer

Word: I am unclear on what the GeometryReader is for in your code — you declare it, then use UIScreen dimensions — usually in SwiftUI we simply use GeometryReader


Leave a Reply

Your email address will not be published. Required fields are marked *