Bug in type()?

The following snippet of code was copied directly from Swift documentation:

func printInfo(_ value: Any) {
    let t = type(of: value)
    print("'\(value)' of type '\(t)'")
}

Xcode 11.2.1 is giving the following error:

Cannot invoke 'type' with an argument list of type '(of: Any)'

on the second line of this snippet of code.

Is this a bug or has something changed that I'm not aware of?

Cheers,
-Patrick

Do you have another function named type defined somewhere that it's finding instead? You could try Swift.type(of: value) if there's a contextual naming conflict.

2 Likes

That fixes the issue. Thank you!

Terms of Service

Privacy Policy

Cookie Policy