Skip to content

Commit

Permalink
Core: conform our identity protocol to Swift.Identifiable
Browse files Browse the repository at this point in the history
  • Loading branch information
djbe committed Jul 25, 2023
1 parent c076d48 commit ec9e7a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion AppwiseCore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pod::Spec.new do |s|
:type => 'MIT',
:file => 'LICENSE'
}
s.ios.deployment_target = '10.0'
s.ios.deployment_target = '13.0'
s.swift_version = '5.0'

# files
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
* Core: add `requestVoid` method to network client.
* Core: default error parser now ignores `.explicitlyCancelled` (for cancelled requests).
* Core: result "cancellation" now uses Swift's built-in `CancellationError` type if available.
* Core: `TaggedIdentifiable` protocol now conforms to Swift's own `Identifiable` protocol.
* XcodeGen: added a template for shared frameworks.

### Bug Fixes
Expand Down
16 changes: 10 additions & 6 deletions Sources/Core/Identity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,29 @@ public protocol _TaggedIdentifiable {
// Note: once we remove `OptionalIdentifiable`, unify this protocol with `TaggedIdentifiable` below.

/// The backing raw type of this type's identifier.
associatedtype RawIdentifier
associatedtype RawIdentifier: Hashable

/// The object type (hack needed to support subclasses)
associatedtype IdentifierObjectType: _TaggedIdentifiable = Self

/// Shorthand type alias for this type's identifier.
typealias TaggedID = Identifier<IdentifierObjectType>

// swiftlint:disable type_name
/// Shorthand type alias for this type's identifier.
typealias ID = Identifier<IdentifierObjectType>
///
/// - Warning: Prefer `TaggedID` to avoid ambiguity errors.
typealias ID = TaggedID
// swiftlint:enable type_name
}

/// Protocol used to mark a given type as being identifiable, meaning
/// that it has a type-safe identifier, backed by a raw value, which
/// defaults to String.
public protocol TaggedIdentifiable: _TaggedIdentifiable {
public protocol TaggedIdentifiable<RawIdentifier>: _TaggedIdentifiable, Swift.Identifiable {
// swiftlint:disable identifier_name
/// The ID of this instance.
var id: ID { get }
var id: TaggedID { get }
// swiftlint:enable identifier_name
}

Expand Down Expand Up @@ -138,7 +143,6 @@ public typealias Identifiable = TaggedIdentifiable
@available(*, deprecated, message: "Will be removed in next major version")
public protocol OptionalIdentifiable: _TaggedIdentifiable {
// swiftlint:disable identifier_name
/// The ID of this instance.
var id: ID? { get }
var id: TaggedID? { get }
// swiftlint:enable identifier_name
}
6 changes: 3 additions & 3 deletions Sources/CoreData/Repository/SingleObjectRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import CoreData
public protocol SingleObjectRepository {
associatedtype ObjectType: NSFetchRequestResult, _TaggedIdentifiable

var objectID: Identifier<ObjectType> { get }
var objectID: ObjectType.TaggedID { get }
var context: NSManagedObjectContext { get }
var object: ObjectType? { get }

init(objectID: Identifier<ObjectType>, context: NSManagedObjectContext)
init(objectID: ObjectType.TaggedID, context: NSManagedObjectContext)
func refresh(then handler: @escaping (Result<ObjectType, Error>) -> Void)
}

// MARK: - Default implementations

public extension SingleObjectRepository {
init(objectID: Identifier<ObjectType>) {
init(objectID: ObjectType.TaggedID) {
self.init(objectID: objectID, context: DB.shared.view)
}

Expand Down

0 comments on commit ec9e7a5

Please sign in to comment.