Skip to content

Commit

Permalink
Added validation calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Fiel Guhit committed May 28, 2014
1 parent cd7b7a1 commit 3d71d46
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Realm/RLMObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "RLMSchema.h"
#import "RLMObjectStore.h"
#import "RLMQueryUtil.h"
#import "RLMUtil.h"

#import <objc/runtime.h>

Expand Down Expand Up @@ -59,21 +60,16 @@ +(instancetype)createInRealm:(RLMRealm *)realm withObject:(id)values {

// FIXME - this can be optimized by inserting directly into the table
// after validation, rather than populating the object first
if ([values isKindOfClass:NSDictionary.class]) {
if ([values isKindOfClass:NSDictionary.class] && RLMValidateValuesForDictionary(values, [self className], realm)) {
// if a dictionary, use key value coding to populate our object
for (NSString *key in values) {
[obj setValue:values[key] forKeyPath:key];
}
}
else if ([values isKindOfClass:NSArray.class]) {
else if ([values isKindOfClass:NSArray.class] && RLMValidateValuesForArray(values, [self className], realm)) {
// for arrays use property names as keys
NSArray *array = values;
RLMObjectSchema *desc = realm.schema[self.className];
NSArray *properties = desc.properties;
if (array.count != desc.properties.count) {
@throw [NSException exceptionWithName:@"RLMException" reason:@"Invalid array input. Number of array elements does not match number of properties." userInfo:nil];
}
// FIXME - more validation for each property type
NSArray *properties = RLMPropertiesForClassName([self className], realm);

for (NSUInteger i = 0; i < array.count; i++) {
[obj setValue:array[i] forKeyPath:[properties[i] name]];
Expand Down

0 comments on commit 3d71d46

Please sign in to comment.