Skip to content

Commit

Permalink
Migrate example to TCA 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rcasula committed Sep 14, 2023
1 parent f3ef59e commit ca60abb
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 278 deletions.
410 changes: 214 additions & 196 deletions Examples/LocationManager/Common/AppCore.swift

Large diffs are not rendered by default.

29 changes: 22 additions & 7 deletions Examples/LocationManager/Common/LocalSearchClient/Client.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import ComposableArchitecture
import MapKit
import Dependencies

extension DependencyValues {
public var localSearchClient: LocalSearchClient {
get { self[LocalSearchClient.self] }
set { self[LocalSearchClient.self] = newValue }
}
}

extension LocalSearchClient: TestDependencyKey {
public static let previewValue = Self.noop
public static let testValue = Self.failing
}

extension LocalSearchClient {
public static let noop = Self(
search: { _ in try await Task.never() }
)
}

public struct LocalSearchClient {
public var search: (MKLocalSearch.Request) -> EffectPublisher<LocalSearchResponse, Error>
public var search: @Sendable (MKLocalSearch.Request) async throws -> LocalSearchResponse

public init(
search: @escaping (MKLocalSearch.Request) -> EffectPublisher<LocalSearchResponse, Error>
search: @escaping @Sendable (MKLocalSearch.Request) async throws -> LocalSearchResponse
) {
self.search = search
}

public struct Error: Swift.Error, Equatable {
public init() {}
}
}

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ComposableArchitecture
import XCTestDynamicOverlay
import MapKit

extension LocalSearchClient {
public static let failing = Self(
search: { _ in .failing("LocalSearchClient.search") }
search: { _ in unimplemented("LocalSearchClient.search") }
)
}
21 changes: 6 additions & 15 deletions Examples/LocationManager/Common/LocalSearchClient/Live.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@ import Combine
import ComposableArchitecture
import MapKit

extension LocalSearchClient {
public static let live = LocalSearchClient(
search: { request in
EffectPublisher.future { callback in
MKLocalSearch(request: request).start { response, error in
switch (response, error) {
case let (.some(response), _):
callback(.success(LocalSearchResponse(response: response)))

case (_, .some):
callback(.failure(LocalSearchClient.Error()))

case (.none, .none):
fatalError("It should not be possible that response and error are both nil.")
}
extension LocalSearchClient: DependencyKey {
public static let liveValue = Self(
search: { request in
let response = try await MKLocalSearch(request: request).start()
return LocalSearchResponse(response: response)
}
}
})
)
}
4 changes: 3 additions & 1 deletion Examples/LocationManager/Common/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public class MapViewCoordinator: NSObject, MKMapViewDelegate {
}

public func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
self.mapView.region = CoordinateRegion(coordinateRegion: mapView.region)
DispatchQueue.main.async {
self.mapView.region = CoordinateRegion(coordinateRegion: mapView.region)
}
}
}
22 changes: 19 additions & 3 deletions Examples/LocationManager/LocationManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@
Base,
);
mainGroup = CA17CC0024720BBA00BDDF11;
packageReferences = (
6AD0AA612AB2F8A4006D9BEA /* XCRemoteSwiftPackageReference "swift-composable-architecture" */,
);
productRefGroup = CA17CC0A24720BBA00BDDF11 /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -491,7 +494,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -547,7 +550,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand All @@ -563,13 +566,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 463J8W9QEQ;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Mobile/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.LocationManager;
PRODUCT_BUNDLE_IDENTIFIER = dev.casula.LocationManager;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -581,6 +585,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 463J8W9QEQ;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = Mobile/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -768,6 +773,17 @@
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
6AD0AA612AB2F8A4006D9BEA /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pointfreeco/swift-composable-architecture";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.2.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
CA17CC3824720BEB00BDDF11 /* ComposableArchitecture */ = {
isa = XCSwiftPackageProductDependency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/combine-schedulers",
"state" : {
"revision" : "ec62f32d21584214a4b27c8cee2b2ad70ab2c38a",
"version" : "0.11.0"
"revision" : "9dc9cbe4bc45c65164fa653a563d8d8db61b09bb",
"version" : "1.0.0"
}
},
{
"identity" : "swift-case-paths",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "fc45e7b2cfece9dd80b5a45e6469ffe67fe67984",
"version" : "0.14.1"
"revision" : "5da6989aae464f324eef5c5b52bdb7974725ab81",
"version" : "1.0.0"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "0fbaebfc013715dab44d715a4d350ba37f297e4d",
"version" : "0.4.0"
"revision" : "d1fd837326aa719bee979bdde1f53cd5797443eb",
"version" : "1.0.0"
}
},
{
Expand All @@ -39,64 +39,64 @@
{
"identity" : "swift-composable-architecture",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture",
"location" : "git@github.com:pointfreeco/swift-composable-architecture.git",
"state" : {
"revision" : "9f4202ab5b8422aa90f0ed983bf7652c3af7abf0",
"version" : "0.59.0"
"revision" : "a7c1f799b55ecb418f85094b142565834f7ee7c7",
"version" : "1.2.0"
}
},
{
"identity" : "swift-concurrency-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
"state" : {
"revision" : "479750bd98fac2e813fffcf2af0728b5b0085795",
"version" : "0.1.1"
"revision" : "ea631ce892687f5432a833312292b80db238186a",
"version" : "1.0.0"
}
},
{
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "4a87bb75be70c983a9548597e8783236feb3401e",
"version" : "0.11.1"
"revision" : "edd66cace818e1b1c6f1b3349bb1d8e00d6f8b01",
"version" : "1.0.0"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "16fd42ae04c6e7f74a6a86395d04722c641cccee",
"version" : "0.6.0"
"revision" : "4e1eb6e28afe723286d8cc60611237ffbddba7c5",
"version" : "1.0.0"
}
},
{
"identity" : "swift-identified-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-identified-collections",
"state" : {
"revision" : "d01446a78fb768adc9a78cbb6df07767c8ccfc29",
"version" : "0.8.0"
"revision" : "d1e45f3e1eee2c9193f5369fa9d70a6ddad635e8",
"version" : "1.0.0"
}
},
{
"identity" : "swiftui-navigation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation",
"state" : {
"revision" : "2aa885e719087ee19df251c08a5980ad3e787f12",
"version" : "0.8.0"
"revision" : "6eb293c49505d86e9e24232cb6af6be7fff93bd5",
"version" : "1.0.2"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "50843cbb8551db836adec2290bb4bc6bac5c1865",
"version" : "0.9.0"
"revision" : "23cbf2294e350076ea4dbd7d5d047c1e76b03631",
"version" : "1.0.2"
}
}
],
Expand Down
Loading

0 comments on commit ca60abb

Please sign in to comment.