[swift-users] Confusing doc re: metatype type, also doesn't compile on linux

Mish Awadah mawadah at apple.com
Mon Dec 7 20:33:26 CST 2015


Could you please file a bug mentioning where the code example was taken from? 

Thanks,
- mish

> On Dec 7, 2015, at 5:11 PM, Karl Pickett via swift-users <swift-users at swift.org> wrote:
> 
> This code example:
> 
> if someInstance.dynamicType === someInstance.self {
>     print("The dynamic and static type of someInstance are the same")
> } else {
>     print("The dynamic and static type of someInstance are different")
> }
> // prints "The dynamic and static type of someInstance are different”
> 
> Does not compile on Linux.   It also is quite confusing - comparing a type === an instance?  It compiles on my mac but is it using some objc weirdness or simply a bug? 
> 
> I think the example means to do something like this:
> 
> // Note: === won't compile
> if SomeBaseClass.self == someInstance.dynamicType {
>     print("is base")
> } else if SomeSubClass.self == someInstance.dynamicType {
>     print("is subclass")
> } else {
>     print("is neither!")
> }
> 
> One other minor typo:
> 
> “// and the runtime type of someInstance is SomeBaseClass”
> 
> should be SomeSubClass.
> 
> 
> 
>  _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151207/80f68c37/attachment.html>


More information about the swift-users mailing list