类和协议的Swift Typealias

时间:2017-03-15 11:32:32

标签: swift types

我有一个必须是UIView的变量,它也实现了协议MTMathKeyboard

我试过了,

var keyboard: (UIView & MTMathKeyboard)
var keyboard: UIView<MTMathKeyboard>

实现协议的非泛型类实例的语法是什么?

4 个答案:

答案 0 :(得分:4)

在Swift 4中,您可以使用:

let keyboard: UIView & MTMathKeyboard

答案 1 :(得分:3)

我认为你应该这样:

update AM1 from  DB1.AM_7541 AM1,
(sel  
distinct TRIM(SB.BUILDING_NAME) NEID, 
trim( leading '0' from sb.MAN) LCDMNO,
AM.Netw_equip,
LAST_TRANSACTION_DATE,
DISCONNECT_DATE,
SEQUENCE_NUMBER
from DB1.PLTL SB
inner join DB1.AM_7541 AM
on  trim( leading '0' from sb.MAN)=AM.AM_NUM
where (SB.LAST_TRANSACTION_DATE,trim(sb.MAN),SB.SEQUENCE_NUMBER)
in  ( sel max(LAST_TRANSACTION_DATE),trim(MAN) lcdmno,max(cast(SEQUENCE_NUMBER as integer))
from DB1.PLTL 
where DISCONNECT_DATE ='2500-01-01 00:00:00' and trim(lcdmno) not like '' 
and lcdmno is not null    
group by lcdmno
)
and TRIM(SB.BUILDING_NAME) not like ''
and DISCONNECT_DATE ='2500-01-01 00:00:00'
) der
set Netw_equip=der.NEID
where AM1.AM_NUM=der.lcdmno

答案 2 :(得分:0)

您可以使用协议组合并扩展UIView以满足占位符协议:

protocol UIViewClass {}
extension UIView:UIViewClass {}


var keyboard :  UIViewClass & MTMathKeyboard

答案 3 :(得分:-1)

typealias KeyboardView = UIView & MTMathKeyboard

protocol MTMathKeyboard: class {
}

private func updateController(with view: KeyboardView) {
        someView = view
}