-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathValidator.swift
More file actions
59 lines (45 loc) · 2.03 KB
/
Copy pathValidator.swift
File metadata and controls
59 lines (45 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Validator.swift
// JSONModelKit
//
// Created by Anton Doudarev on 7/17/15.
// Copyright © 2015 Ustwo. All rights reserved.
//
import Foundation
final class Validator {
// MARK Validates that all the non-optional values were received or defaulted
final class func validateResponse(forValues retrievedValues : Dictionary<String, Any>,
mappedTo mappingConfiguration : Dictionary<String, Dictionary<String, AnyObject>>,
forType className : String,
withData data : Dictionary<String, AnyObject>) -> Bool {
var missingPropertyKeyArray = Array<String>()
// Validate that all non-optional properties have a value assigned
for (propertyKey, propertyMapping) in mappingConfiguration {
if let isPropertyNonOptional : AnyObject = propertyMapping[JMMapperNonOptionalKey] {
if isPropertyNonOptional.boolValue == true {
if let _ = retrievedValues[propertyKey] {
// If value was mapped, continue with validation
continue
} else {
if JMConfig.debugEnabled {
missingPropertyKeyArray.append(propertyKey)
} else {
return false
}
}
}
}
}
if JMConfig.debugEnabled {
if missingPropertyKeyArray.count > 0 {
print("\n\n\(className) instance could not be parsed, missing values for the following non-optional properties:")
for propertyKey in missingPropertyKeyArray {
print("\n- \(propertyKey)")
}
print("\n\nResponse:\n\(data)\n\n")
return false
}
}
return true
}
}