0

There's lots of past questions relating to this but all the ones I could find are for when you want to determine if an object is of a certain type of class (if myClassInstance is MyClassType {...}).

I want to know how I can determine if object A and object B are of the same class type without having to know/specify what that type is.

Hamish
  • 78,605
  • 19
  • 187
  • 280
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378

1 Answers1

0

I stand corrected - .classForCoder only works for NSObjectProtocol conforming types.

Better answers are available.

This might do what you're looking for...

class MyClassTypeA: NSObject {

}

class MyClassTypeB: NSObject {

}

var a = MyClassTypeA()
var b = MyClassTypeB()
var c = MyClassTypeB()

print(a.isKind(of: b.classForCoder))
print(a.isKind(of: c.classForCoder))
print(b.isKind(of: c.classForCoder))

DonMag
  • 69,424
  • 5
  • 50
  • 86