Skip to content

Commit

Permalink
Primitive lists in realm
Browse files Browse the repository at this point in the history
  • Loading branch information
Vermeer, Edwin authored and Vermeer, Edwin committed Oct 22, 2017
1 parent cf62410 commit b728999
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 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.1.3"
s.version = "5.1.4"
s.summary = "Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift"

s.description = <<-EOS
Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions Source/EVReflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,9 @@ final public class EVReflection {
valid = isValid
} else if !type.hasPrefix("Swift.Array<") && !type.hasPrefix("Swift.Set<") {
if let array = dictValue as? NSArray {
if anyObject is EVCustomReflectable {
return (array, true)
}
if let org = anyObject as? EVReflectable {
org.addStatusMessage(.InvalidType, message: "Did not expect an array for \(key). Will use the first item instead.")
evPrint(.InvalidType, "WARNING: Did not expect an array for \(key). Will use the first item instead.")
Expand Down
7 changes: 6 additions & 1 deletion Source/Realm/RealmListEVCustomReflectable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ extension List : EVCustomReflectable {
self.append(element)
}
}

} else if let array = value as? NSArray {
for item in array {
if let element: Element = item as? Element {
self.append(element)
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion UnitTests/RealmTestIssue221.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import EVReflection

class CategoryModel: Object, EVReflectable {

@objc dynamic var children = ""
let children = List<String>()
@objc dynamic var id = ""
@objc dynamic var isRoot = false
let name = List<NameCategoryModel>()
Expand Down
10 changes: 9 additions & 1 deletion UnitTests/RealmTests/RealmTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class Car: Object, EVReflectable {
}
}

class PrimitiveListsObject: Object, EVReflectable {
let strings = List<String>()
let optionalInt = RealmOptional<Int>()
}


/**
Expand Down Expand Up @@ -135,9 +139,13 @@ class RealmTests: XCTestCase {
print("Number of persons in database after delete = \(realm.objects(Person.self).count)")
//: Thanks! To learn more about Realm go to https://realm.io
}

func testPrimitiveLists() {
let obj = PrimitiveListsObject(json: "{\"strings\":[\"a\",\"b\",\"c\"]}")
print("The object: \(obj)")
}
}





0 comments on commit b728999

Please sign in to comment.