diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aaf4055fc..84f4554594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ x.y.z Release notes (yyyy-MM-dd) * Conform `@ThreadSafe` and `ThreadSafeReference` to `Sendable`. ### Fixed +* Fix `RLMCollectionIterator` where `RLMCollectionIterator` contents were not RLMObject. + This is for users using the optional `RLMSupport.swift` file. +* Change default request timeout for `RLMApp` from 6 seconds to 60 seconds. * Allow `@AutoOpen` to return a realm for any server error on synchronisation. * Do not allow `progress` state changes for `@AutoOpen` and `@AsyncOpen` after changing state to `open(let realm)` or `error(let error)`. diff --git a/Realm/Swift/RLMSupport.swift b/Realm/Swift/RLMSupport.swift index ab3c840ab9..2ec596ec9b 100644 --- a/Realm/Swift/RLMSupport.swift +++ b/Realm/Swift/RLMSupport.swift @@ -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? } } diff --git a/Realm/Tests/Swift/SwiftArrayTests.swift b/Realm/Tests/Swift/SwiftArrayTests.swift index 4b4057fa1d..a5fcd90d4a 100644 --- a/Realm/Tests/Swift/SwiftArrayTests.swift +++ b/Realm/Tests/Swift/SwiftArrayTests.swift @@ -513,4 +513,29 @@ class SwiftRLMArrayTests: RLMTestCase { XCTAssertEqual(Int32(20), (sortedByAge[0] as! EmployeeObject).age) XCTAssertEqual(Int32(40), (sortedByName[0] as! EmployeeObject).age) } + + func testRLMArrayIterationForObjectAndNonObjectTypes() { + let rlmArrayEmbedded = RLMArray(objectClassName: EmbeddedIntObject.className()) + let obj = EmbeddedIntObject() + obj.intCol = 42 + rlmArrayEmbedded.add(obj) + for obj in rlmArrayEmbedded { + XCTAssertEqual(obj.intCol, 42) + } + + let rlmArrayObject = RLMArray(objectClassName: IntObject.className()) + let intObject = IntObject() + intObject.intCol = 42 + rlmArrayObject.add(intObject) + for obj in rlmArrayObject { + XCTAssertEqual(obj.intCol, 42) + } + + let rlmArrayPrimitive = RLMArray(objectClassName: "NSString") + let str = "foo" + rlmArrayPrimitive.add(str as NSString) + for obj in rlmArrayPrimitive { + XCTAssertEqual(obj as! NSString, "foo" as NSString) + } + } }