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
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:
Replies
Boosts
Views
Activity
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.
Replies
Boosts
Views
Activity
Dec ’21
Reply to Make app available only for iPhone only not ipads
So for now we want to make our app available for iPhones only. Is there any way to do that? > NO. If you make your app for targeting iPhone only, your app needs to run on the simulator mode (3.5' screen) of iPad. Fix your app to run on iPad or make it target for both iPhone and iPad. The only other alternative is abandoning to publish it on the App Store.
Replies
Boosts
Views
Activity
Dec ’21