"as" in Swift

"as" in Swift,第1张

概述逐条解释一下,熟悉 “as”的用法,是“as”,不是“as?”和 “as!”: for thing in things { switch thing { case 0 as Int: print("zero as an Int") case 0 as Double: print("zero as a Double") case l

逐条解释一下,熟悉 “as”的用法,是“as”,不是“as?”和 “as!”:

for thing in things {    switch thing {    case 0 as Int:        print("zero as an Int")    case 0 as Double:        print("zero as a Double")    case let someInt as Int:        print("an integer value of \(someInt)")    case let someDouble as Double where someDouble > 0:        print("a positive double value of \(someDouble)")    case is Double:        print("some other double value that I donot want to print")    case let someString as String:        print("a string value of \"\(someString)\"")    case let (x,y) as (Double,Double):        print("an (x,y) point at \(x),\(y)")    case let movIE as MovIE:        print("a movIE called \(movIE.name),dir.\(movIE.director)")    case let stringConverter as (String) -> String:        print(stringConverter("Michael"))    default:        print("something else")    }}
(1) 0 as Int(2) 0 as Double
总结

以上是内存溢出为你收集整理的"as" in Swift全部内容,希望文章能够帮你解决"as" in Swift所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1064311.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存