Swift mode protocol HeaderViewProtocol { func setTitle(_ string: String) } struct AnyHeaderView { let view: UIView let headerView: HeaderViewProtocol init<T: UIView>(view: T) where T: HeaderViewProtocol { self.view = view self.headerView = view } } let header = AnyHeaderView(view: myView) header.headerView.setTitle("hi") struct HeaderView { let view: UIView let setTitle: (String) -> () } var label = UILabel() let header = HeaderView(view: label) { str in label.text = str } header.setTitle("hello") xxxxxxxxxx 1protocol HeaderViewProtocol {2 func setTitle(_ string: String)3}45struct AnyHeaderView {6 let view: UIView7 let headerView: HeaderViewProtocol8 init<T: UIView>(view: T) where T: HeaderViewProtocol {9 self.view = view10 self.headerView = view11 }12}1314let header = AnyHeaderView(view: myView)15header.headerView.setTitle("hi")1617struct HeaderView {18 let view: UIView19 let setTitle: (String) -> ()20}2122var label = UILabel()23let header = HeaderView(view: label) { str in24 label.text = str25}26header.setTitle("hello")27 A simple mode for Swift MIME types defined: text/x-swift (Swift code)