Skip to content

Commit

Permalink
remove some "Any" protocols
Browse files Browse the repository at this point in the history
swift generics have progressed since then!
  • Loading branch information
juliand665 committed Jan 27, 2024
1 parent 0c9787b commit af46cbd
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 21 deletions.
8 changes: 1 addition & 7 deletions Issue Manager/Back End/Objects/Base/ObjectMeta.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Foundation
import GRDB

struct ObjectMeta<Object: StoredObject>: AnyObjectMeta, Codable, Equatable {
struct ObjectMeta<Object: StoredObject>: Codable, Equatable {
var id = Object.ID()
var lastChangeTime = Date.distantPast // intentionally wrong to not throw off most recent lastChangeTime for sync
var isDeleted = false
Expand All @@ -20,9 +20,3 @@ extension ObjectMeta: DBRecord where Object: DBRecord {
case isDeleted
}
}

protocol AnyObjectMeta {
var rawID: String { get }
var lastChangeTime: Date { get }
var isDeleted: Bool { get }
}
7 changes: 1 addition & 6 deletions Issue Manager/Back End/Objects/Base/StoredObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Foundation
import GRDB

protocol StoredObject: AnyStoredObject {
protocol StoredObject: DBRecord, Sendable {
typealias ID = ObjectID<Self>
typealias Meta = ObjectMeta<Self>

Expand All @@ -26,7 +26,6 @@ extension StoredObject {

var id: ID { meta.id }

var rawMeta: AnyObjectMeta { meta }
var rawID: String { id.rawValue }
var isDeleted: Bool { meta.isDeleted }
}
Expand All @@ -37,10 +36,6 @@ extension DerivableRequest where RowDecoder: StoredObject {
}
}

protocol AnyStoredObject: DBRecord, Sendable {
var rawID: String { get }
}

// pure value types: of course they're sendable
extension QueryInterfaceRequest: @unchecked Sendable {}
extension BelongsToAssociation: @unchecked Sendable {}
Expand Down
4 changes: 2 additions & 2 deletions Issue Manager/Back End/Objects/MapHolder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Foundation
import GRDB

protocol MapHolder: AnyStoredObject {
protocol MapHolder: StoredObject {
var name: String { get }
var children: Map.Query { get }
var constructionSiteID: ConstructionSite.ID { get }
Expand All @@ -28,7 +28,7 @@ extension MapHolder {

extension DerivableRequest where RowDecoder == Map {
@MainActor
func recursiveChildren(of holder: MapHolder) -> Self {
func recursiveChildren(of holder: some MapHolder) -> Self {
holder.recursiveChildren(in: self)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Issue Manager/Issue Manager/Common/IssueBadge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class IssueBadge: UIView {
}

var shouldUseRecursiveIssues = true
var holder: MapHolder! {
var holder: (any MapHolder)! {
didSet { update() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class MapListViewController: RefreshingTableViewController, InstantiableVi

@IBOutlet private var backToSiteListButton: UIBarButtonItem!

var holder: MapHolder! {
var holder: (any MapHolder)! {
didSet { update() }
}

Expand Down Expand Up @@ -149,17 +149,18 @@ final class MapListViewController: RefreshingTableViewController, InstantiableVi
mapController.holder = holder
}
} else {
showMapController(for: holder)
let h = holder! // awkward work around for implicit existential opening not opening IUOs
showMapController(for: h)
}
}

func showMapController(for holder: MapHolder) {
func showMapController(for holder: some MapHolder) {
let mapController = MapViewController.instantiate()!
mapController.holder = holder
show(mapController, sender: self)
}

func showListController(for holder: MapHolder) {
func showListController(for holder: some MapHolder) {
let listController = MapListViewController.instantiate()!
listController.holder = holder
show(listController, sender: self)
Expand Down
2 changes: 1 addition & 1 deletion Issue Manager/Issue Manager/Map/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ final class MapViewController: UIViewController, InstantiableViewController {
var isMovingIssue: Bool { editorForPlacingIssue != nil }
private var editorForPlacingIssue: EditIssueViewController?

var holder: MapHolder? {
var holder: (any MapHolder)? {
didSet { update() }
}
var map: Map? { holder as? Map }
Expand Down

0 comments on commit af46cbd

Please sign in to comment.