Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for iOS 16 #7

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// swift-tools-version:5.8
// swift-tools-version: 5.8
import PackageDescription

let package = Package(
name: "SwiftRepo",
platforms: [
.iOS("18.0"),
.iOS("16.0"),
.macOS("15.0"),
],
products: [
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftRepo/Repository/ModelResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
/// Partnered with a `QueryRepository` using an additional model store, `Value` will be
/// propagated via an `ObservableStore` and the array of `Model`s will be placed in
/// the `ModelStore`.
@available(iOS 17, *)
public protocol ModelResponse {
/// Can be used to propagate additional metadata related to the response via an `ObservableStore`
associatedtype Value
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftRepo/Repository/Protocols/Query/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public extension Query {
/// - strategy: The query strategy
/// - willGet: A closure that will be called if and when the query is performed. This is typically the `LoadingController.loading` function.
/// - Returns: The value if the query was performed. Otherwise, `nil`.
@available(iOS 17, *)
func get<Store, Key, ModelStore>(
id: QueryId,
variables: Variables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ where QueryId: Hashable, Variables: Hashable, Key: Hashable {
/// - modelStore: The underlying `Store` implementation to use for `QueryValue.Model`.
/// - queryStrategy: The query strategy to use.
/// - queryOperation: The operation to use to perform the actual query.
@available(iOS 17, *)
public init<Model, QueryValue>(
observableStore: ObservableStoreType,
modelStore: any Store<Model.Key, Model>,
Expand Down Expand Up @@ -148,6 +149,7 @@ where QueryId: Hashable, Variables: Hashable, Key: Hashable {
/// - modelStore: The underlying `Store` implementation to use for models.
/// - queryStrategy: The query strategy to use.
/// - queryOperation: The operation to use to perform the actual query.
@available(iOS 17, *)
public convenience init<Model>(
observableStore: ObservableStoreType,
modelStore: any Store<Model.Key, Model>,
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftRepo/Repository/Store/PersistentStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import SwiftData

/// A persistent `Store` implementation implementation using `SwiftData`.
@available(iOS 18, *)
public class PersistentStore<Key: Codable & Hashable, Value: Codable>: Store {

public var keys: [Key] {
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftRepo/Repository/Store/SwiftDataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftData
import SwiftRepoCore

// An implementation of `Store` that uses `SwiftData` under the hood
@available(iOS 18, *)
public class SwiftDataStore<Model: StoreModel>: Store where Model: PersistentModel, Model.Key: Hashable & Codable {
public typealias Key = Model.Key
public typealias Value = Model
Expand Down
9 changes: 5 additions & 4 deletions Sources/SwiftRepo/Repository/StoreModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
/// This interface is to be used with models that will be retrieved by the app
/// through database queries, rather than published by a `QueryRepository`,
/// such as when using SwiftData.
@available(iOS 17, *)
public protocol StoreModel {
/// The type to use as the identifier for the model
associatedtype Key = any Hashable
Expand All @@ -21,7 +22,7 @@ public protocol StoreModel {
/// A predicate that can be used to query for the `StoreModel`
static func predicate(key: Key) -> Predicate<Self>
}

@available(iOS 17, *)
public extension StoreModel where Key == Data {

static func predicate(key: Key) -> Predicate<Self> {
Expand All @@ -30,7 +31,7 @@ public extension StoreModel where Key == Data {
}
}
}

@available(iOS 17, *)
public extension StoreModel where Key == UUID {

static func predicate(key: Key) -> Predicate<Self> {
Expand All @@ -39,7 +40,7 @@ public extension StoreModel where Key == UUID {
}
}
}

@available(iOS 17, *)
public extension StoreModel where Key == String {

static func predicate(key: Key) -> Predicate<Self> {
Expand All @@ -48,7 +49,7 @@ public extension StoreModel where Key == String {
}
}
}

@available(iOS 17, *)
public extension StoreModel where Key == Int {

static func predicate(key: Key) -> Predicate<Self> {
Expand Down
13 changes: 10 additions & 3 deletions Sources/SwiftRepo/SwiftUI/LoadingControllerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public struct LoadingControllerView<DataType, Content, LoadingContent, ErrorCont

public var body: some View {
loadingControllerView
.onChange(of: state) { loadedErrorData = state.loadedIndispensableUIError as? UIErrorType }
.onChange(of: state) { _ in
loadedErrorData = state.loadedIndispensableUIError as? UIErrorType }
}

private var loadingControllerView: some View {
Expand All @@ -65,8 +66,14 @@ public struct LoadingControllerView<DataType, Content, LoadingContent, ErrorCont
}
// Make this view greedy so that it occupies the same space across all loading states.
.frame(maxWidth: .infinity, maxHeight: .infinity)
// This keeps animations together if new animations are created while other animations are in progress.
.geometryGroup()
.viewAsArgument { view in
if #available(iOS 17, *) {
// This keeps animations together if new animations are created while other animations are in progress.
view.geometryGroup()
} else {
view.transformEffect(.identity)
}
}
.animation(.default, value: state)
.refreshable { [weak refresh] in
await refresh?.refresh(retryError: nil)
Expand Down
14 changes: 14 additions & 0 deletions Sources/SwiftRepo/SwiftUI/View+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// View+Extensions.swift
// SwiftRepo
//
// Created by Carlos De La Mora on 12/4/24.
//

import SwiftUI

extension View {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you changes this to the following (to match what we use in Bootstrap)?

    /// Provides a way to introduce a code block as a view modifier.
    @ViewBuilder func map<Content: View>(@ViewBuilder _ transform: (Self) -> Content) -> some View {
        transform(self)
    }

func viewAsArgument(@ViewBuilder modifier:(Self) -> some View) -> some View {
modifier(self)
}
}
5 changes: 5 additions & 0 deletions Tests/SwiftRepoTests/DefaultQueryRepositoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DefaultQueryRepositoryTests: XCTestCase {
XCTAssertEqual(spy.publishedValues, [valueA1, valueA1, valueA1, valueA2])
}

@available(iOS 17, *)
@MainActor
func test_GetSuccess_ModelResponse() async throws {
let repo = makeModelResponseStoreRepository(
Expand Down Expand Up @@ -59,6 +60,7 @@ class DefaultQueryRepositoryTests: XCTestCase {
XCTAssertEqual(try modelStore.get(key: Self.modelCId), responseB.models.last)
}

@available(iOS 17, *)
@MainActor
func test_GetSuccess_ModelResponse_Trim() async throws {
let repo = makeModelResponseStoreRepository(
Expand Down Expand Up @@ -98,6 +100,7 @@ class DefaultQueryRepositoryTests: XCTestCase {
XCTAssertEqual(spy.publishedValues.compactMap { $0 as? TestError }, [TestError(category: .failure)])
}

@available(iOS 17, *)
func test_GetError_ModelResponse() async throws {
let repo = makeModelResponseStoreRepository(
delayedValues: DelayedValues<TestModelResponse>(values: [
Expand Down Expand Up @@ -234,6 +237,7 @@ class DefaultQueryRepositoryTests: XCTestCase {
var id: UUID
var updatedAt = Date()

@available(iOS 17, *)
static func predicate(key: UUID) -> Predicate<DefaultQueryRepositoryTests.TestModelResponse.TestStoreModel> {
#Predicate { $0.id == key }
}
Expand Down Expand Up @@ -294,6 +298,7 @@ class DefaultQueryRepositoryTests: XCTestCase {

/// Makes a repository that stores a single value per unique query ID,
/// and places ModelResponse values in a separate model store.
@available(iOS 17, *)
private func makeModelResponseStoreRepository(
mergeStrategy: ModelStoreMergeStrategy = .upsertAppend,
queryStrategy: QueryStrategy = .ifOlderThan(0.1),
Expand Down
1 change: 1 addition & 0 deletions Tests/SwiftRepoTests/SwiftDataStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import XCTest
import SwiftData
@testable import SwiftRepo

@available(iOS 18, *)
@MainActor
class SwiftDataStoreTests: XCTestCase {

Expand Down