Adding SwiftUI to Objective-C Apps

Field Notes on freshening up legacy iOS apps

//
// BoatDetailsView.swift
//
import SwiftUIstruct BoatDetailsView : View {
var shipName = ""
var body: some View {
Text(shipName)
}
}
//
// BoatDetailsInterface.swift
//
import Foundation
import SwiftUI
@objc
class BoatDetailsInterface: NSObject {

@objc func makeShipDetailsUI(_ name: String) -> UIViewController{
var details = BoatDetailsView()
details.shipName = name
return UIHostingController(rootView: details)
}
}
#import "Boat_Watch-Swift.h"
UIViewController *detailsViewController = [[BoatDetailsInterface new] makeShipDetailsUI:@"Sarita"];[self presentModalViewController:detailsViewController animated:YES];

Emerging Technology R&D • PhD student, researching Blockchain, AI and Crowdworking • Mobile, IOT & Alexa App coder and product manager