2016-08-03 3 views
1

필자는 인수 유형을 확인하는 함수가 있지만 모든 유형 주석과 함께 작동 할 수있는 매개 변수를 정의하는 것은 어렵습니다. 여기에 나의-노력하고 있어요 :유형 주석이없는 매개 변수 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(//argument)) 
// 
+3

왜 그렇게하고 싶습니까? 당신이 해결하려고하는 실제 문제는 무엇입니까? –

답변

0

당신은 자신을 대답

[...] 와 함께 작업 할 수있는 유형 [...]

여기에 코드

입니다
func checkType(input: Any) -> String { 
    let res = "That is of type \(input.dynamicType)" 
    return res 
} 

테스트

checkType("Hello") // "That is of type String" 
checkType(true) // "That is of type Bool" 
checkType(123) // "That is of type Int" 
+0

완벽하게 작동합니다. 고맙습니다! – Bool

+1

누군가가이 정답을 downvote했습니다, 다음번에 downvotes을 설명해주십시오. –