Skip to content

Commit

Permalink
memory leak fix
Browse files Browse the repository at this point in the history
  • Loading branch information
evermeer committed Jun 10, 2018
1 parent ea8ed32 commit 54ce05f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion EVReflection.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "EVReflection"
s.version = "5.6.1"
s.version = "5.6.2"
s.summary = "Reflection based object mapping. (Dictionary, CKRecord, NSManagedObject, Realm, JSON, XML, Alamofire, Moya, RxSwift, ReactiveSwift)"

s.description = <<-EOS
Expand Down
Binary file not shown.
5 changes: 4 additions & 1 deletion Source/EVReflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,10 @@ final public class EVReflection {
do {
if !(value is NSNull) {
var setValue: AnyObject? = value as AnyObject?
try anyObject.validateValue(&setValue, forKey: key)
let validateFunction = "validate" + key.prefix(1).uppercased() + key.dropFirst() + ":error:"
if (anyObject as AnyObject).responds(to: Selector(validateFunction)) {
try anyObject.validateValue(&setValue, forKey: key)
}
anyObject.setValue(setValue, forKey: key)
}
} catch _ {
Expand Down
5 changes: 5 additions & 0 deletions UnitTests/EVReflectionTests/EVReflectionIssue84.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ class TestIssue84: XCTestCase {

}
}





7 changes: 7 additions & 0 deletions UnitTests/EVReflectionTests/EVReflectionMappingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class EVReflectionMappingTests: XCTestCase {
XCTAssertNil(player.memberSince)
XCTAssertEqual(player.rating, 0)
}

func testValidationFunction() {
let user = GameUser(json: "{\"name\":\"Yo\"}")
XCTAssertNil(user.name, "Name should not have been set to Yo")
let user2 = GameUser(json: "{\"name\":\"Yol\"}")
XCTAssertEqual(user2.name, "Yol", "Name should have been set to Yol")
}
}

enum MyValidationError: Error {
Expand Down

0 comments on commit 54ce05f

Please sign in to comment.