Swift mode protocol HeaderViewProtocol { func setTitle(_ string: String) } struct AnyHeaderView { let view: UIView let headerView: HeaderViewProtocol init(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") A simple mode for Swift MIME types defined: text/x-swift (Swift code)