Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ObjC Support iteration #7498

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ x.y.z Release notes (yyyy-MM-dd)
* None.

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-cocoa/issues/????), since v?.?.?)
* None.
* Fix `RLMCollectionIterator` where `RLMCollectionIterator` contents were not RLMObject.
This is for users using the optional `RLMSupport.swift` file.

<!-- ### Breaking Changes - ONLY INCLUDE FOR NEW MAJOR version -->

Expand Down
4 changes: 2 additions & 2 deletions Realm/Swift/RLMSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public struct RLMCollectionIterator: IteratorProtocol {
iteratorBase = NSFastEnumerationIterator(collection)
}

public mutating func next() -> RLMObject? {
return iteratorBase.next() as! RLMObject?
public mutating func next() -> AnyObject? {
return iteratorBase.next() as AnyObject?
}
}

Expand Down
23 changes: 23 additions & 0 deletions RealmSwift/Tests/ObjectiveCSupportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,27 @@ class ObjectiveCSupportTests: TestCase {
}
expected.forEach { testObjCSupport($0.0, value: $0.1) }
}

#if !SWIFT_PACKAGE
func testArraySupport() {
let list = List<SwiftObject>()
let obj = SwiftObject()
list.append(obj)
obj.doubleCol = 42.42
let rlmArray = ObjectiveCSupport.convert(object: list)
XCTAssert(rlmArray.isKind(of: RLMArray<AnyObject>.self))
for object in rlmArray {
XCTAssertEqual(obj.doubleCol, object.value(forKey: "doubleCol") as? Double)
}

let primitiveList = List<Double>()
let double = 42.42
primitiveList.append(double)
let primitiveRLMArray = ObjectiveCSupport.convert(object: primitiveList)
XCTAssert(primitiveRLMArray.isKind(of: RLMArray<AnyObject>.self))
for object in primitiveRLMArray {
XCTAssertEqual(double, object as? Double)
}
}
#endif
}