1 year ago

#379547

test-img

Impish

(SwiftUI) Function for saving item to a list only displaying one option from an array out of four?

I'm trying to build something of a dummy book store/shopping app. Something about this function is only displaying one option out of four written in an array...but I'm not sure why? Essentially, what this does is allow a user to add this to a list out of a searchable selection...except it's somehow decided that all of the options are only the first one?

The Function itself:

func addToWishList() {
guard !search.trimmingCharacters(in: .whitespaces).isEmpty else {
return
}
let NewBook = NewBook.self
viewModel.featureissues.append(NewBook)
search = ""
}
}

The Class with published var:

class ComicIssueCardViewModel: ObservableObject {

@Published var featureissues = [
book(id: 1, title: "Book One", image: "IMG1", details: " Sample Details"),
book(id: 2, title: "Book Two", image: "IMG2", details: "Sample Details"),
book(id: 3, title: "Book Three", image: "IMG3", details: "Sample Details"),
book(id: 4, title: "Book Four", image: "IMG4" "Sample Details")
]
}

Also, the UUID struct:

struct featureissues: Identifiable{
var id = UUID()
var title: String
}

xcode

swiftui

swiftui-list

0 Answers

Your Answer

Accepted video resources