Swift学习小结之泛型

前端之家收集整理的这篇文章主要介绍了Swift学习小结之泛型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
import UIKit

var str = "Hello,playground"
//泛型
func repeat<ItemType>(item : ItemType,times:Int)->ItemType[]{

   var result = ItemType[]()
    for i in 0..times{
      result += item
    
    }
     return result

}
repeat("knock",4)

enum OptionalValue<T>{
  case None
  case Some(T)
}
var possibleInteger : OptionalValue<Int> = .None
possibleInteger = .Some(100)

func anyComminElements<T,U where T: Sequence,U : Sequence,T.GeneratorType.Element: Equatable,t.GeneratorType.Elment == U.GeneratorType.Element> (1hs:T,rhs :U)->Bool{
    for ihsItem in ihs {
        for rhsItem in rhs {
            if ihsItem == rhsItem {
               return true
              }
        }
    }
       return  false
}
anyComminElements([1,2,3],[3])

<T: Equatable>
<T where T: Equatable>
原文链接:https://www.f2er.com/swift/327547.html

猜你在找的Swift相关文章