Check for value or reference type in Swift

后端 未结 2 1857
死守一世寂寞
死守一世寂寞 2021-01-03 03:59

How can we check if a parameter passed in a function is a value or a reference type? For example

func isReferenceType(toTest: Any) {
    return true // or fa         


        
2条回答
  •  离开以前
    2021-01-03 04:53

    Swift 5

    func isReferenceType(_ toTest: Any) -> Bool {
        return type(of: toTest) is AnyClass
    }
    

提交回复
热议问题