Swift 不带类型注释的参数
我有一个函数来检查它接受的参数的类型,但是我似乎很难定义一个可以用于任何类型注释的参数。以下是我一直在尝试的:Swift 不带类型注释的参数,swift,Swift,我有一个函数来检查它接受的参数的类型,但是我似乎很难定义一个可以用于任何类型注释的参数。以下是我一直在尝试的: //bool var x = 0, y = 3.142, z = "hello" func checkType(input: /*here's my problem*/) -> String { let res = "That is of type \(input.dynamicType)" return res } print(checkType(//argu
//bool
var x = 0, y = 3.142, z = "hello"
func checkType(input: /*here's my problem*/) -> String {
let res = "That is of type \(input.dynamicType)"
return res
}
print(checkType(//argument))
//
你自己回答
[…]可以与任何类型一起使用[…]
这是密码
func checkType(input: Any) -> String {
let res = "That is of type \(input.dynamicType)"
return res
}
试验
你自己回答
[…]可以与任何类型一起使用[…]
这是密码
func checkType(input: Any) -> String {
let res = "That is of type \(input.dynamicType)"
return res
}
试验
你为什么要这么做?你想解决的实际问题是什么?你为什么要这样做?你试图解决的实际问题是什么?出于某种原因,有人否决了这个正确答案,请下次解释你的否决票。出于某种原因,有人否决了这个正确答案,请下次解释你的否决票。。