Skip to content

iOS Development – Week 4

There was a lot to cover in Week 4 and I am glad I was able to complete all the assignments for this week, including the nice-to-haves. The focus of this week was UIKit and how it can integrate with SwiftUI. We were asked to keep an eye to spot differences between UIKit and SwiftUI on how both of them work, what differences they see in the frameworks, and so on. We were asked to create lists with a UITableView for UIKit and a ForEach loop iterating over views for SwiftUI.

Some of the most interesting aspects this week included the interfacing between SwiftUI and UIKit with UIViewRepresentable and UIHostingController.

It was really interesting to see how SwiftUI can be used in conjunction with in production apps that are building with UIKit.

UIViewRepresentable

UIViewRepresentable protocol requires confirmation for two methods.

associatedtype UIViewType: UIView
func makeUIView(context: Self.Context) -> Self.UIViewType
func updateUIView(_ uiView: Self.UIViewType, context: Self.Context)

The makeUIView method should create a UIKit view and returns it for SwiftUI to handle. SwiftUI calls this method when the view is created. Then updateUIView is called when your view should be updated. Both methods bring you a UIViewRepresentableContext struct which you can use to get Coordinator or various environment values.

UIHostingController

UIHostingController creates a bridge between UIKit and SwiftUI framework. It works as a Container View for SwiftUI view, meaning you can use it as normal UIViewController. The purpose of the UIHostingController is to enclose a SwiftUI view so that it can be integrated into an existing UIKit based project. Using a HostingViewController, a SwiftUI view can be treated either as an entire scene (occupying the full screen) or as an individual component within an existing UIKit scene.

Jelly Belly – Update

This time we were using SwiftUI and UIKit to build a Restaurant Menu. For my menu view. I have updated the prototype design for my app:

I have implemented the following:

A new menu when clicking the SF Symbol with the fork and knife. It shows the following view:

  • Order – The old order view I had from previous weeks. Runs with test data in the Simulator (not shown)
  • Menu – SwiftUI – Assignment 2 for this week’s homework. Tapping on each row displays a detailed view of the dish
  • Menu – UIKit – Assignment 1 for this week’s homework
  • Menu – UIKit List – An attempt to build a table programmatically (effectively bonus). This was my own experiment – it is not finished, but did not want to delete it

Week 5 – bring it on!

Related Posts

Tags:

1 thought on “iOS Development – Week 4”

  1. Pingback: iOS Development – Week 1 – Quantum Tunnel

Comments are closed.