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

Code before:
            if ([obj isKindOfClass:[NSNumber class]]) {
                return nsnumber_is_like_integer(obj);
            }
            return [obj isKindOfClass:[NSDate class]];
        case RLMPropertyTypeInt:
            if ([obj isKindOfClass:[NSNumber class]]) {
                return nsnumber_is_like_integer(obj);
            }
            return NO;
        case RLMPropertyTypeFloat:
            if ([obj isKindOfClass:[NSNumber class]]) {
                return nsnumber_is_like_float(obj);
            }
            return NO;
        case RLMPropertyTypeDouble:
            if ([obj isKindOfClass:[NSNumber class]]) {
                return nsnumber_is_like_double(obj);
            }
            return NO;
        case RLMPropertyTypeData:
            return [obj isKindOfClass:[NSData class]];
        case RLMPropertyTypeAny:
            return [obj isKindOfClass:[NSObject class]];
        // FIXME: missing entries
        case RLMPropertyTypeObject:
        case RLMPropertyTypeArray:
            break;
    }
    @throw [NSException exceptionWithName:@"RLMException" reason:@"Invalid RLMPropertyType specified" userInfo:nil];
}


void RLMSetAnyProperty(tightdb::Table &table, NSUInteger row_ndx, NSUInteger col_ndx, id obj) {
//    if (obj == nil) {
//        table.nullify_link(col_ndx, row_ndx);
//        return;
//    }
    if ([obj isKindOfClass:[NSString class]]) {
        table.set_mixed(col_ndx, row_ndx, RLMStringDataWithNSString(obj));
        return;
    }
    if ([obj isKindOfClass:[NSDate class]]) {
        table.set_mixed(col_ndx, row_ndx, tightdb::DateTime(time_t([(NSDate *)obj timeIntervalSince1970])));
        return;
    }
    if ([obj isKindOfClass:[NSData class]]) {
        table.set_mixed(col_ndx, row_ndx, RLMBinaryDataForNSData(obj));
        return;
    }
    if ([obj isKindOfClass:[NSNumber class]]) {
        const char *data_type = [(NSNumber *)obj objCType];

Review comment (suggestion):
This is not right - it will always return true unless the object is nil. We should be checking if the object is of any valid type.


Code after:
                return nsnumber_is_like_bool(obj);
            }
            return NO;
        case RLMPropertyTypeDate:
            if ([obj isKindOfClass:[NSNumber class]]) {
                return nsnumber_is_like_integer(obj);
            }
            return [obj isKindOfClass:[NSDate class]];
        case RLMPropertyTypeInt:
            if ([obj isKindOfClass:[NSNumber class]]) {
                return nsnumber_is_like_integer(obj);
            }
            return NO;
        case RLMPropertyTypeFloat:
            if ([obj isKindOfClass:[NSNumber class]]) {
                return nsnumber_is_like_float(obj);
            }
            return NO;
        case RLMPropertyTypeDouble:
            if ([obj isKindOfClass:[NSNumber class]]) {
                return nsnumber_is_like_double(obj);
            }
            return NO;
        case RLMPropertyTypeData:
            return [obj isKindOfClass:[NSData class]];
        case RLMPropertyTypeAny:
            return object_has_valid_type(obj);
            
        // FIXME: missing entries
        case RLMPropertyTypeObject:
        case RLMPropertyTypeArray:
            break;
    }
    @throw [NSException exceptionWithName:@"RLMException" reason:@"Invalid RLMPropertyType specified" userInfo:nil];
}


void RLMSetAnyProperty(tightdb::Table &table, NSUInteger row_ndx, NSUInteger col_ndx, id obj) {
//    if (obj == nil) {
//        table.nullify_link(col_ndx, row_ndx);
//        return;
//    }
    if ([obj isKindOfClass:[NSString class]]) {
        table.set_mixed(col_ndx, row_ndx, RLMStringDataWithNSString(obj));
        return;
    }
    if ([obj isKindOfClass:[NSDate class]]) {
        table.set_mixed(col_ndx, row_ndx, tightdb::DateTime(time_t([(NSDate *)obj timeIntervalSince1970])));
        return;
    }
    if ([obj isKindOfClass:[NSData class]]) {