How do I determine whether two instances of a generic struct are of the same type?
For example, given the following struct:
struct FooBar<T> {
let variable: T
init(arg: T) {
variable = arg
}
}
And the following snippet:
let foo = FooBar(1)
let bar = FooBar(1.0)
let baz = FooBar("1")
How can I determine whether foo
, bar
, or baz
are of the same or different types?
func areExactType(x: FooBar) -> Bool {
return self.dynamicType === x.dynamicType
}
This gives
Type 'Foo' does not conform to protocol 'AnyObject'
func areExactType(x: FooBar) -> Bool {
return self.dynamicType === x.dynamicType
}
This gives
Cannot invoke '==' with an argument list of type '(Foo.Type, Foo.Type)'
func areExactType(x: FooBar) -> Bool {
return self is x.dynamicType
}
This gives three errors:
Consecutive statements on a line must be separated by ';'
(this wants to put a semicolon between the period and 'dynamicType')
Expected identifier in dotted type
and
Expected expression