 
     return class_getRootSuperclass(superclass)
 }
+
+fileprivate func allClasses() -> [AnyClass] {
+    let expectedClassCount = objc_getClassList(nil, 0) * 2
+    let allClasses = UnsafeMutablePointer<AnyClass?>.allocate(capacity: Int(expectedClassCount))
+    let autoreleasingAllClasses = AutoreleasingUnsafeMutablePointer<AnyClass?>(allClasses)  // Huh? We should have gotten this for free.
+    let actualClassCount = objc_getClassList(autoreleasingAllClasses, expectedClassCount)
+
+    var classes = [AnyClass]()
+    for i in 0 ..< actualClassCount {
+        if let currentClass: AnyClass = allClasses[Int(i)] {
+            classes.append(currentClass)
+        }
+    }
+
+    allClasses.deallocate(capacity: Int(expectedClassCount))
+
+    return classes
+}

public func allSubclassesOf<T>(_ baseClass: T) -> [T] {
    var matches: [T] = []

    // Get all the classes which implement 'baseClass' and return them
    // Helped by code from https://gist.github.com/bnickel/410a1bdc02f12fbd9b5e
    let expectedClassCount = objc_getClassList(nil, 0)
    let allClasses = UnsafeMutablePointer<AnyClass?>.allocate(capacity: Int(expectedClassCount))
    let autoreleasingAllClasses = AutoreleasingUnsafeMutablePointer<AnyClass?>(allClasses) // Huh? We should have gotten this for free.
    let actualClassCount = objc_getClassList(autoreleasingAllClasses, expectedClassCount)

    for i in 0..<actualClassCount {

        guard let currentClass = allClasses[Int(i)] else {
            continue
        }

        guard class_getRootSuperclass(currentClass) == NSObject.self else {
            continue

        }
    }

    return matches
}

