Confusing doc re: metatype type, also doesn't compile on linux

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.

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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-users