Skip to content

Instantly share code, notes, and snippets.

@hsleedevelop
Created August 12, 2022 12:29
Show Gist options
  • Save hsleedevelop/35ea06ab8acaefbdc7361d68c0b7b038 to your computer and use it in GitHub Desktop.
Save hsleedevelop/35ea06ab8acaefbdc7361d68c0b7b038 to your computer and use it in GitHub Desktop.
Representable Implements
//
// DialogOneButtonView.swift
//
// Created by HS Lee on 2022/08/08.
//
import Foundation
import UIKit
import SwiftUI
protocol DesignSystem {
associatedtype T
static func create() -> T
}
class DialogView: NibLoadableView, DesignSystem {
typealias T = DialogView
required override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
func commonInit() {
}
func representable() -> Representable<T> {
logD("T.self=\(T.self)")
return Representable()
}
class func create() -> T {
return Self.init(frame: .zero)
}
struct Representable<T: DesignSystem>: UIViewRepresentable {
func updateUIView(_ uiView: UIViewType, context: Context) {
}
func makeUIView(context: Context) -> some UIView {
logD(T.self)
return autocast(some: T.create())!
}
}
}
@IBDesignable
class DialogOneButtonView: DialogView {
typealias T = DialogOneButtonView
@IBOutlet weak var titleLabel: Title_subhead_06bLabel!
@IBOutlet weak var bodyLabel: Body_body_03rLabel!
@IBOutlet weak var primaryButtton: PrimaryRoundedButton!
override func commonInit() {
super.commonInit()
}
override func draw(_ rect: CGRect) {
super.draw(rect)
// Drawing code
self.backgroundColor = .blue
}
func representable() -> Representable<T> {
logD("T.self=\(T.self)")
return Representable()
}
override class func create() -> T {
return DialogOneButtonView(frame: CGRect.init(x: 0, y: 0, width: 240, height: 120)) as! Self
}
}
func autocast<T>(some: Any?) -> T? {
return some as? T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment