Skip to content

Commit

Permalink
Fix retroactive conformance warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed Jun 18, 2024
1 parent 652358d commit 9e935a6
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 6 deletions.
9 changes: 8 additions & 1 deletion Realm/Swift/RLMSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension RLMObject {
}

/// A protocol defining iterator support for RLMArray, RLMSet & RLMResults.
public protocol _RLMCollectionIterator {
public protocol _RLMCollectionIterator: Sequence {
/**
Returns a `RLMCollectionIterator` that yields successive elements in the collection.
This enables support for sequence-style enumeration of `RLMObject` subclasses in Swift.
Expand Down Expand Up @@ -97,10 +97,17 @@ extension _RLMDictionaryIterator where Self: RLMCollection {

// Sequence conformance for RLMArray, RLMDictionary, RLMSet and RLMResults is provided by RLMCollection's
// `makeIterator()` implementation.
#if compiler(<6.0)
extension RLMArray: Sequence, _RLMCollectionIterator { }
extension RLMDictionary: Sequence, _RLMDictionaryIterator {}
extension RLMSet: Sequence, _RLMCollectionIterator {}
extension RLMResults: Sequence, _RLMCollectionIterator {}
#else
extension RLMArray: @retroactive Sequence, _RLMCollectionIterator { }
extension RLMDictionary: @retroactive Sequence, _RLMDictionaryIterator {}
extension RLMSet: @retroactive Sequence, _RLMCollectionIterator {}
extension RLMResults: @retroactive Sequence, _RLMCollectionIterator {}
#endif

/**
This struct enables sequence-style enumeration for RLMObjects in Swift via `RLMCollection.makeIterator`
Expand Down
7 changes: 6 additions & 1 deletion RealmSwift/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,19 @@ public struct AppPublisher: Publisher, @unchecked Sendable { // DispatchQueue
}

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension App: ObservableObject {
extension App {
/// A publisher that emits Void each time the app changes.
///
/// Despite the name, this actually emits *after* the app has changed.
public var objectWillChange: AppPublisher {
return AppPublisher(self, scheduler: DispatchQueue.main)
}
}
#if compiler(>=6)
extension App: @retroactive ObservableObject {}
#else
extension App: ObservableObject {}
#endif

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
internal func promisify(_ fn: @escaping (@escaping @Sendable (Error?) -> Void) -> Void) -> Future<Void, Error> {
Expand Down
16 changes: 14 additions & 2 deletions RealmSwift/Combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ extension Realm {
// MARK: - Object

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Object: ObservableObject {
extension Object {
/// A publisher that emits Void each time the object changes.
///
/// Despite the name, this actually emits *after* the object has changed.
Expand All @@ -621,7 +621,7 @@ extension Object: ObservableObject {
}
}
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension EmbeddedObject: ObservableObject {
extension EmbeddedObject {
/// A publisher that emits Void each time the object changes.
///
/// Despite the name, this actually emits *after* the embedded object has changed.
Expand All @@ -647,6 +647,18 @@ extension ObjectBase: RealmSubscribable {
}
}

#if compiler(>=6)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Object: @retroactive ObservableObject {}
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension EmbeddedObject: @retroactive ObservableObject {}
#else
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Object: ObservableObject {}
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension EmbeddedObject: ObservableObject {}
#endif

// MARK: - List

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
Expand Down
4 changes: 4 additions & 0 deletions RealmSwift/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ extension Realm.Error {

// MARK: Equatable

#if compiler(>=6)
extension Realm.Error: @retroactive Equatable {}
#else
extension Realm.Error: Equatable {}
#endif

// FIXME: we should not be defining this but it's a breaking change to remove
/// Returns a Boolean indicating whether the errors are identical.
Expand Down
7 changes: 6 additions & 1 deletion RealmSwift/Impl/ObjcBridgeable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,16 @@ extension ResultsSection: BuiltInObjcBridgeable {
}
}

extension RLMSwiftCollectionBase: Equatable {
extension RLMSwiftCollectionBase {
public static func == (lhs: RLMSwiftCollectionBase, rhs: RLMSwiftCollectionBase) -> Bool {
return lhs.isEqual(rhs)
}
}
#if compiler(>=6)
extension RLMSwiftCollectionBase: @retroactive Equatable {}
#else
extension RLMSwiftCollectionBase: Equatable {}
#endif

extension Projection: BuiltInObjcBridgeable {
public static func _rlmFromObjc(_ value: Any) -> Self? {
Expand Down
10 changes: 9 additions & 1 deletion RealmSwift/Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ public class UserPublisher: Publisher {
}

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension User: ObservableObject {
extension User {
/// A publisher that emits Void each time the user changes.
///
/// Despite the name, this actually emits *after* the user has changed.
Expand All @@ -1107,6 +1107,14 @@ extension User: ObservableObject {
}
}

#if compiler(>=6)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension User: @retroactive ObservableObject {}
#else
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension User: ObservableObject {}
#endif

public extension User {
// NEXT-MAJOR: This function returns the incorrect type. It should be Document
// rather than `[AnyHashable: Any]`
Expand Down
12 changes: 12 additions & 0 deletions RealmSwift/Tests/ObjectSchemaInitializationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ class SwiftObjectWithNonOptionalLinkProperty: SwiftFakeObject {
@objc dynamic var objectCol = SwiftBoolObject()
}

#if compiler(<6)
extension Set: RealmOptionalType {
public static func _rlmFromObjc(_ value: Any, insideOptional: Bool) -> Set<Element>? {
fatalError()
Expand All @@ -815,6 +816,17 @@ extension Set: RealmOptionalType {
fatalError()
}
}
#else
extension Set: @retroactive RealmOptionalType {
public static func _rlmFromObjc(_ value: Any, insideOptional: Bool) -> Set<Element>? {
fatalError()
}

public var _rlmObjcValue: Any {
fatalError()
}
}
#endif

@available(*, deprecated) // Silence deprecation warnings for RealmOptional
class SwiftObjectWithNonRealmOptionalType: SwiftFakeObject {
Expand Down
9 changes: 9 additions & 0 deletions RealmSwift/Tests/RealmTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1894,12 +1894,21 @@ extension RealmTests {
static var shared = CustomGlobalActor()
}

#if compiler(<6)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension CancellationError: Equatable {
public static func == (lhs: CancellationError, rhs: CancellationError) -> Bool {
true
}
}
#else
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension CancellationError: @retroactive Equatable {
public static func == (lhs: CancellationError, rhs: CancellationError) -> Bool {
true
}
}
#endif

// Helper
extension LogLevel {
Expand Down

0 comments on commit 9e935a6

Please sign in to comment.