Drawing SwiftUI with ObservableObject
Contacts DiffableDataSource
Let's have a fun lesson in drawing SwiftUI views inside of our UIKit applications. Doing this will be really helpful in creating your user interface as well as provide an easy road for maintenance when the time comes.

Comments (7)
ZpecterZ80
3 years ago
Hi Brian, How can we get the name of every section directly from the datasource? Thank you very much.
Anubhav06
2 years ago
you can get from snapshot.
Munish Sehdev
3 years ago
Hi Brian, I recently started watching your video from youtube and really liked them. I am leaning diffableDatasource from this video but unable to understand fillSuperview() method. Can you give me some details in which video you showed this method or give me the details here for it? Thanks in advance
Allen Xu
3 years ago
hostingController.view.fillSuperview() dosent work
Allen Xu
3 years ago
If I dont user LBTATools, what I can use to replace in here
Allen Xu
3 years ago
I have solved this problem, thanks.
Tokyojogo
3 years ago
How did you fix it? Having that problem too (fillSuperView())
omair_34
3 years ago
You can try this: hostingController.view.topAnchorConstraint(equalTo: self.topAnchor).isActive = true hostingController.view.leftAnchorConstraint(equalTo: self.leftAnchor).isActive = true hostingController.view.rightAnchorConstraint(equalTo: self.rightAnchor).isActive = true hostingController.view.bottomAnchorConstraint(equalTo: self.bottomAnchor).isActive = true
omair_34
3 years ago
and also hostingController.view.translatesAutoResizingMasksIntoConstraints = false
mmbolshakova
3 years ago
How did you solve that?
omair_34
3 years ago
fillSuperView() function also contains the same lines of code thats why.
Mohsen9april
3 years ago
Worked ! Thanks
Mohsen9april
3 years ago
hostingController.view.fillSuperview() doesn't work but This is Work , try This struct ContactRowView: View { var body: some View { HStack{ Image(systemName: "person.fill") Text("Some Contacts") Spacer() Image(systemName: "star") } } } class ContactCell: UITableViewCell { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) // backgroundColor = .red let hostingController = UIHostingController(rootView: ContactRowView()) self.addSubview(hostingController.view) hostingController.view.translatesAutoresizingMaskIntoConstraints = false hostingController.view.topAnchor.constraint(equalTo: self.topAnchor).isActive = true hostingController.view.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true hostingController.view.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true hostingController.view.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }
Matthew Easton
3 years ago
Works for me, thanks!
MaxApp
3 years ago
Hey Brian, why are you not importing UIKit? Because I do see some class such as the UITableViewController!
Peter Aupils Lapisu
3 years ago
SwiftUI is pure shit... this would be 10x more easier and much more clear using regular UIKit
jimmy hernandez
3 years ago
Oh Yeah
Matthew MacbethTEST
2 years ago
Hey the " hostingController.view.fillSuperview()" does not work , Not sure what to do?
Brian Voong
2 years ago
HELP & SUPPORT