使用Tuple打包数据

使用Tuple打包数据,第1张

概述//(Int, String)let success = (200, "Http Ok") //(.0 200, .1 "Http Ok")let fileNotFound:(Int, String) = (404, "File not found") //(.0 404, .1 "File not found")type(of:success) //(Int, String)
//(Int,String)let success = (200,"http Ok")  //(.0 200,.1 "http Ok")let @R_301_6852@NotFound:(Int,String) = (404,"@R_301_6852@ not found")    //(.0 404,.1 "@R_301_6852@ not found")type(of:success)    //(Int,String).Typesuccess.0   //200success.1   //"http Ok"//(String,Int,String)let xiaoming = (name:"xiaoming",no:01,email:"11@1111.com")    //(.0 "xiaoming",.1 1,.2 "11@1111.com")xiaoming.name   //"xiaoming"xiaoming.no //1xiaoming.email  //"11@1111.com"//Tuple decompositionvar (successCode,successMessage) = successsuccessCode = 201   //不会影响success,只是把success的值放进模型内successMessage  //"http Ok"success //(.0 200,.1 "http Ok")let (_,errorMessage) = @R_301_6852@NotFound    //不需要的参数可以用 _ 表示忽略errorMessage    //"@R_301_6852@ not found"//只有成员个数相同的Tuple能相互比较let tuple11 = (1,1)let tuple12 = (1,2)tuple11 < tuple12   //truetuple11 == tuple12  //falselet tuple123 = (1,2,3)//tuple12 == tuple123 //错误,成员个数不相同//另外成员个数超过6个的Tuple相互比较会编译错误let tuple61 = (1,3,4,5,6)let tuple62 = (1,6)tuple61 == tuple62  //truelet tuple71 = (1,6,7)let tuple72 = (1,7)//tuple71 == tuple72 //错误

//参考自SwiftV课堂视频源码

总结

以上是内存溢出为你收集整理的使用Tuple打包数据全部内容,希望文章能够帮你解决使用Tuple打包数据所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存