ios - 元组中的类型推断?

标签 ios swift tuples

let http404Error = (statusCode: 404, statusMessage: "Not found")
print(http404Error.0, http404Error.1)

我对元组有一些疑问和“问题”:

问题1:
但是如果我希望 statusCode 既是 Int 又是 Int 该怎么办?
因为“statusCode: Int = 404”似乎不起作用?

问题2:
如果我想缩短“print(http404Error.0, http404Error.1)”部分怎么办?
有没有一种简短的写法,比如 print(http404Error.[0, 1])?

感谢您的帮助:)

最佳答案

你可以试试

let http404Error:(Int,String) = (statusCode: 404, statusMessage: "Not found")

关于ios - 元组中的类型推断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55306632/

相关文章:

ios - 没有匹配函数调用 'ellipse'

ios - 如何在不下载的情况下从url获取图像的宽度和高度?

ios - 以编程方式更改 ECSlidingViewController 中的 View

swift - 父类(super class)上的通用便利 init() 受限于已初始化对象的子类?

python - 分配给 python : a bug? 中的可变元组组件是一个特性吗?

ios - Firebase Auth 不起作用,但适用于 friend ,很快

ios - 如何在 Swift 中保存 CoreGraphics 绘图

matlab - swift 是否有等效的 "eval"函数,就像在 Matlab 中一样?

python - 将 python Dataframe 转换为 Matlab 文件

java - 如何在一个方法中返回一对对象?