Post

Replies

Boosts

Views

Activity

Reply to Referencing initializer 'init(_:content:)' on 'ForEach' requires that 'Image' conform to 'Identifiable'
As you can find in the error message, each element passed to ForEach needs to conform to Identifiable (or easily provide id to identify). You should better think Image is not a good thing to hold in an Array and use with ForEach. One possible solutions would be holding UIImage (or CGImage) in an Array: Something like this: struct FilterView: View{ @State var image: Image? let filteredUIImage: [UIImage] //<- var body: some View { NavigationView{ ZStack{ //... VStack { //... ScrollView(.horizontal, showsIndicators: false) { HStack{ ForEach(filteredUIImage, id: \.self) { uiImage in //<- //... } } } } } } .toolbar { //... } } //... } And creating a local variable holding a view does not make sense. You need to update your loadFilter(): struct ContentView: View { //... @State var filteredUIImage: [UIImage] = [] //<- //... var body: some View { //... .navigate(to: FilterView(image: image, filteredUIImage: filteredUIImage), when: $showingFilterView) //<- } //... func loadFilter() { filteredUIImage = [] filters.forEach { (filters) in //... let uiImage = UIImage(cgImage: cgimg!) //let filteredImage = Image(uiImage: uiImage) //Creating a view as local variable does not make sense // let filterView = FilterView() // filterView.filteredImage.append(filteredImage) filteredUIImage.append(uiImage) } } } I'm not sure if this is the best solution for your purpose, generally having many images in an array would not be recommended.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’21
Reply to Xcode
Xcode 13 has changed many things, how to handle Info.plist, storyboard format, project templates and so on. You may need to find a good tutorial about what's new in Xcode 13 or get an older version of Xcode.
Dec ’21