Skip to content

Instantly share code, notes, and snippets.

View jasperblues's full-sized avatar

Jasper Blues jasperblues

  • Earth (Mostly Australia & Philippines)
View GitHub Profile
@jasperblues
jasperblues / SwiftUIAdapter
Last active December 23, 2020 02:50
Adapter allowing a UIKit controller to be backed by a SwiftUI view.
class SwiftUIAdapter<Content> where Content : View {
private(set) var view: Content!
weak private(set) var parent: UIViewController!
private(set) var uiView : WrappedView
var hostingController: UIHostingController<Content>
init(view: Content, parent: UIViewController) {
self.view = view
self.parent = parent
const flatten = arr => arr.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);
flatten([[1, 2, [3]], 4]);