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
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users