Skip to content

Commit

Permalink
fix Realm Objective-C's Swift 3 extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Sep 8, 2016
1 parent 912b12a commit 7d5a1b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 38 deletions.
35 changes: 12 additions & 23 deletions Realm/Swift/RLMSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import Realm

#if swift(>=3.0)
extension RLMRealm {
// TODO: Figure out why this causes the Swift 3 compiler to segfault.
// public class func schemaVersion(at url: URL, usingEncryptionKey key: Data? = nil) throws -> UInt64 {
// var error: NSError?
// let version = __schemaVersion(at: url, encryptionKey: key, error: &error)
// guard version != RLMNotVersioned else {
// throw error!
// }
// return version
// }
@nonobjc public class func schemaVersion(at url: URL, usingEncryptionKey key: Data? = nil) throws -> UInt64 {
var error: NSError?
let version = __schemaVersion(at: url, encryptionKey: key, error: &error)
guard version != RLMNotVersioned else {
throw error!
}
return version
}
}

extension RLMObject {
Expand Down Expand Up @@ -56,20 +55,10 @@ import Realm
}
}

// SR-2348: A bug in Objective-C generics currently make this impossible w/o an error or compiler crash.
// extension RLMArray: Sequence {
// // Support Sequence-style enumeration
// public func makeIterator() -> RLMIterator {
// return RLMIterator(collection: self)
// }
// }
//
// extension RLMResults: Sequence {
// // Support Sequence-style enumeration
// public func makeIterator() -> RLMIterator {
// return RLMIterator(collection: self)
// }
// }
// Sequence conformance for RLMArray and RLMResults is provided by RLMCollection's
// `makeIterator()` implementation.
extension RLMArray: Sequence {}
extension RLMResults: Sequence {}

extension RLMCollection {
// Support Sequence-style enumeration
Expand Down
5 changes: 1 addition & 4 deletions Realm/Tests/Swift/SwiftArrayPropertyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ class SwiftArrayPropertyTests: RLMTestCase {
XCTAssertEqual((array.array[1] as! SwiftStringObject).stringCol, "b", "Second element should have property value 'b'")
XCTAssertEqual((array.array[2] as! SwiftStringObject).stringCol, "a", "Third element should have property value 'a'")

// Temporary fix until we figure out why iterators segfault
// for obj in array.array {
for i in 0..<array.array.count {
let obj = array.array[i]
for obj in array.array {
XCTAssertFalse(obj.description.isEmpty, "Object should have description")
}
}
Expand Down
10 changes: 2 additions & 8 deletions Realm/Tests/Swift/SwiftArrayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ class SwiftArrayTests: RLMTestCase {

var totalSum = 0

// Temporary fix until we figure out why iterators segfault
// for obj in array.array {
for i in 0..<result.count {
let obj = result[i]
for obj in result {
if let ao = obj as? SwiftAggregateObject {
totalSum += ao.intCol
}
Expand Down Expand Up @@ -282,10 +279,7 @@ class SwiftArrayTests: RLMTestCase {

var totalSum: CInt = 0

// Temporary fix until we figure out why iterators segfault
// for obj in array.array {
for i in 0..<result.count {
let obj = result[i]
for obj in result {
if let ao = obj as? AggregateObject {
totalSum += ao.intCol
}
Expand Down
4 changes: 1 addition & 3 deletions Realm/Tests/Swift/SwiftDynamicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class SwiftDynamicTests: RLMTestCase {
func testDynamicRealmExists() {
autoreleasepool {
// open realm in autoreleasepool to create tables and then dispose
let realm = RLMRealm(url

: RLMTestRealmURL())
let realm = RLMRealm(url: RLMTestRealmURL())
realm.beginWriteTransaction()
_ = SwiftDynamicObject.create(in: realm, withValue: ["column1", 1])
_ = SwiftDynamicObject.create(in: realm, withValue: ["column2", 2])
Expand Down

0 comments on commit 7d5a1b8

Please sign in to comment.