Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 不带类型注释的参数_Swift - Fatal编程技术网

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
}
试验


你为什么要这么做?你想解决的实际问题是什么?你为什么要这样做?你试图解决的实际问题是什么?出于某种原因,有人否决了这个正确答案,请下次解释你的否决票。出于某种原因,有人否决了这个正确答案,请下次解释你的否决票。。