funcrepeat<ItemType>(item:ItemType,count:Int)->[ItemType] {
varresult = [ItemType]();
foriin0..<count {
result.append(item);
}
returnresult;
}
varre =repeat("zxh",4);
println(re);
//泛型枚举
enumOPtion<T>{
caseNone
caseSome(T)
}
varop:OPtion<Int> = .None;
op= .Some(100);
//泛型类
classca<T>{
varv:T;
init(val:T){
v= val;
println(v);
}
}
varcaval =ca<Double>(val:2.2);
原文链接:https://www.f2er.com/swift/326942.html