(OLD) Using coordinators to manage SwiftUI view controllers – Instafilter SwiftUI Tutorial 6/12

preview_player
Показать описание
In this project you'll learn how to incorporate UIKit UIViewControllers into your SwiftUI app.

Рекомендации по теме
Комментарии
Автор

Hey Paul -- you're definitely one of the better tutors on YouTube for Apple developers. Thanks for these videos!

csmaca
Автор

Perhaps this could be more difficult, but I'm not sure how. Thanks for the good explanation. I have my own controller, so I figured I had to make my own delegate protocol and that seemed to work.

ToddHoff
Автор

Awesome explanation! I think we don't need the func loadImage & double image property in contentView in this case. In my code, I add an empty check of inputImage in body view. Then if the image return from ImagePicker is not nil, it will be presented in contentView.


struct ContentView: View {
@State private var showingImagePicker = false
@State private var inputImage: UIImage?

var body: some View {
VStack {
if inputImage != nil {
Image(uiImage: inputImage!)
.resizable()
.scaledToFit()
} else {
// Some place holder here
}

Button("Select Image") {
self.showingImagePicker = true
}
}
.sheet(isPresented: $showingImagePicker) {
ImagePicker(image: self.$inputImage)
}
}
}

ZhouHaibo
Автор

This is hard to remember but it's 12 minutes, so i just refer to this video or to this code and create something similar when i have to. Last time i had to use custom tableview class(it was in fact a viewcontroller with two table views that communicated with each other), and after struggling how to pass selected data to swiftui view, how handle updating the view when array of items is changed(deleted, inserted, moved) and getting confused when it said Coordinator class does not conform to protocol(i mean, what must have i written in cellatrow and numberofsection functions, that i needed to add to Coordinator after conforming to datasource and tableviewdelegate? So i just created simple protocol with one func, an comformed Coordinator to that protocol, an yep! i had to implement just that one func, that passed the data that i wanted. So it is a great workaround to create your own protocol for Coordinator if you want to pass data.

volimpia
Автор

Excellent explanation ! One question: why are two images needed (i.e. image and inputImage) - couldn't we omit image and use inputImage instead (and therefore omit onDismiss and loadImage ? After all, the binding should go all the way, shouldn't it ?

stephankorner
Автор

Any update?

if let uiImage = info[.originalImage] as? UIImage {
parent.image = uiImage
}

the compiler shows no image variable.

chooseyourfuturebeforeitch
Автор

when presenting the picker there is no way to dismiss it (by drag-down) before choosing any image

muradjam
Автор

Thanks for the video. However, for the feature itself, i think it is ridiculously overcomplicated. I'm not sure if Swift(or SwiftUI) is going in the good direction anymore.

Jraz
Автор

So hard! Great tutorial though. I keep getting this error when I run the code, does anyone else experience this?
"Thread 1: Fatal error: Reading outside View.body"

It seems to be related to the line

penelope
Автор

How can the user delete/remove the selected photo?!

pickemparty
Автор

&£!% Apple! What an unholy tangle of code just to present a system-provided image picker! It should be one, two, or maaaaybe three lines of code max! What is even happening? How does makeUIViewController actually get called? What is a context? Why does the coordinator have to be a separate type? I know you tried your best to explain it, but it doesn't work for me. This seems like a whole lot of code that should be Apple's responsibility, not the developer's. Just let me specify a binding and a callback and be done with it... UIKit: not even once. 😵 I can only hope to be able to copy & paste this code correctly when I will need it, let alone understand it, but thank you!

adlsfreund
Автор

But how to use storyboard with view controller to swiftUI, the ibaction didn't work.

vindajojo
welcome to shbcf.ru