Repository: realm/realm-swift
File: Realm/RLMSchema.mm (Objective-C++)

Code before:
    return schema;
}

- (id)init {
    self = [super init];
    if (self) {
        // setup name mapping for object tables
        _tableNamesForClass = [NSMutableDictionary dictionary];
        _objectSchemaByName = [NSMutableDictionary dictionary];
    }
    return self;
}

- (void)setObjectSchema:(NSArray *)objectSchema {
    _objectSchema = objectSchema;
    
    // update mappings
    for (RLMObjectSchema *object in objectSchema) {
        // set table name and mappings
        _tableNamesForClass[object.className] = RLMTableNameForClassName(object.className);
        [(NSMutableDictionary *)_objectSchemaByName setObject:object forKey:object.className];
    }
}

static inline bool IsRLMObjectSubclass(Class cls) {
    Class parent = class_getSuperclass(cls);
    if (!parent || parent != RLMObject.class) {
        for (; parent; parent = class_getSuperclass(parent)) {
            if (parent == RLMObject.class) {
                @throw [NSException exceptionWithName:@"RLMException"
                                               reason:[NSString stringWithFormat:@"Class '%s' inherits from a RLMObject subclass. This is currently not supported. All model classes must inherit directly from RLMObject and cannot have subclasses of their own.",
                                                       class_getName(cls)]
                                             userInfo:nil];
            }
        }
        return false;
    }
    return true;
}

+ (void)initialize {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        // initialize mangled name mapping
        s_classNameToMangledName = [NSMutableDictionary dictionary];

        NSMutableArray *schemaArray = [NSMutableArray array];
        RLMSchema *schema = [[RLMSchema alloc] init];

        unsigned int numClasses;
        Class *classes = objc_copyClassList(&numClasses);

Review comment (suggestion):
This whole method could be rewritten from here:

``` objc
if (parent != RLMObject.class && RLMIsSubclass(parent, RLMObject.class)) {
 @throw...
}
```


Code after:
    return schema;
}

- (id)init {
    self = [super init];
    if (self) {
        // setup name mapping for object tables
        _tableNamesForClass = [NSMutableDictionary dictionary];
        _objectSchemaByName = [NSMutableDictionary dictionary];
    }
    return self;
}

- (void)setObjectSchema:(NSArray *)objectSchema {
    _objectSchema = objectSchema;
    
    // update mappings
    for (RLMObjectSchema *object in objectSchema) {
        // set table name and mappings
        _tableNamesForClass[object.className] = RLMTableNameForClassName(object.className);
        [(NSMutableDictionary *)_objectSchemaByName setObject:object forKey:object.className];
    }
}

static inline bool IsRLMObjectSubclass(Class cls) {
    Class parent = class_getSuperclass(cls);
    if (parent != RLMObject.class) {
        if (parent && RLMIsSubclass(parent, RLMObject.class)) {
            @throw [NSException exceptionWithName:@"RLMException"
                                           reason:[NSString stringWithFormat:@"Class '%s' inherits from a RLMObject subclass. This is currently not supported. All model classes must inherit directly from RLMObject and cannot have subclasses of their own.",
                                                   class_getName(cls)]
                                         userInfo:nil];
        }
        return false;
    }
    return true;
}

+ (void)initialize {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        // initialize mangled name mapping
        s_classNameToMangledName = [NSMutableDictionary dictionary];

        NSMutableArray *schemaArray = [NSMutableArray array];
        RLMSchema *schema = [[RLMSchema alloc] init];

        unsigned int numClasses;
        Class *classes = objc_copyClassList(&numClasses);
        for (unsigned int i = 0; i < numClasses; i++) {
            Class cls = classes[i];