Post

Replies

Boosts

Views

Activity

Reply to Binding UIImage from Image
Hello Claude,this was only for demonstration, not for work.but this not the solution, to change the data type from UIImage to Image, because I need it (datatype UIImage) for further procession in an UIKit View (datatype of struct WorkOnPicture).GreedsDWD
May ’20
Reply to Binding UIImage from Image
Hello Claude,so, I made an Example. The Error occures, wehn teh view "WorkOnPicture" with the Binding will be called. Only the struct ContentView should be modified...import SwiftUI import Combine class GetPicture: ObservableObject {//get picture from everywhere static let shared: GetPicture = GetPicture() let willChange = PassthroughSubject<Image?, Never>() @Published var image: Image? = nil { didSet { if image != nil { willChange.send(image) } } } func get() { image = Image("ExamplePNG") } } struct WorkOnPicture: View { @Binding var image: UIImage var body: some View { Text("Hello Picture") } } struct ContentView: View { @State var image: Image? = nil var body: some View { VStack { image?.resizable().frame(width: 100, height: 100) .contextMenu { Button(action: { self.workWithPicture() }) { Text("Edit") Image(systemName: "pencil") }.disabled(image == nil) } }.onReceive(GetPicture.shared.$image) { image in self.image = image } .onAppear() { GetPicture().get() } } func workWithPicture() { WorkOnPicture(image: image) //<- here is the problem } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }Kind regardsDWD
May ’20