Double primitive type is "AnyObject" however it cannot conform to protocols that require an AnyObject type

Viewed 29

Please explain why this is the case.

let double = Double(1.1)

let anyObject = double as AnyObject

print(double is AnyObject) // 'is' test is always true

The above code generates a warning which is in the comment on the code. It prints "true."

protocol ClassProtocol: AnyObject {
}

extension Double: ClassProtocol { // Non-class type 'Double' cannot conform to class protocol 'ClassProtocol'
}

However, this code above generates the error in the code comment.

0 Answers
Related