Skip to content

Commit b206b3f

Browse files
committed
Set SWIFT_STRICT_CONCURRENCY to complete in EssentialApp and fix all warnings
1 parent cd499d0 commit b206b3f

File tree

12 files changed

+32
-64
lines changed

12 files changed

+32
-64
lines changed

EssentialApp/EssentialApp.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@
508508
SUPPORTS_MACCATALYST = NO;
509509
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
510510
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
511+
SWIFT_APPROACHABLE_CONCURRENCY = YES;
512+
SWIFT_STRICT_CONCURRENCY = complete;
511513
SWIFT_VERSION = 5.0;
512514
TARGETED_DEVICE_FAMILY = 1;
513515
};
@@ -532,6 +534,8 @@
532534
SUPPORTS_MACCATALYST = NO;
533535
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
534536
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
537+
SWIFT_APPROACHABLE_CONCURRENCY = YES;
538+
SWIFT_STRICT_CONCURRENCY = complete;
535539
SWIFT_VERSION = 5.0;
536540
TARGETED_DEVICE_FAMILY = 1;
537541
};
@@ -556,7 +560,9 @@
556560
SUPPORTS_MACCATALYST = NO;
557561
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
558562
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
563+
SWIFT_APPROACHABLE_CONCURRENCY = YES;
559564
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
565+
SWIFT_STRICT_CONCURRENCY = complete;
560566
SWIFT_VERSION = 5.0;
561567
TARGETED_DEVICE_FAMILY = 1;
562568
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/EssentialApp.app/EssentialApp";
@@ -582,6 +588,8 @@
582588
SUPPORTS_MACCATALYST = NO;
583589
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
584590
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
591+
SWIFT_APPROACHABLE_CONCURRENCY = YES;
592+
SWIFT_STRICT_CONCURRENCY = complete;
585593
SWIFT_VERSION = 5.0;
586594
TARGETED_DEVICE_FAMILY = 1;
587595
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/EssentialApp.app/EssentialApp";

EssentialApp/EssentialApp/CombineHelpers.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public extension HTTPClient {
4040

4141
return Deferred {
4242
Future { completion in
43-
task = self.get(from: url, completion: completion)
43+
nonisolated(unsafe) let uncheckedCompletion = completion
44+
task = self.get(from: url, completion: {
45+
uncheckedCompletion($0)
46+
})
4447
}
4548
}
4649
.handleEvents(receiveCancel: { task?.cancel() })
@@ -229,7 +232,8 @@ extension AnyDispatchQueueScheduler {
229232
if store.contextQueue == .main, Thread.isMainThread {
230233
action()
231234
} else {
232-
store.perform(action)
235+
nonisolated(unsafe) let uncheckedAction = action
236+
store.perform { uncheckedAction() }
233237
}
234238
return AnyCancellable {}
235239
}
@@ -238,15 +242,17 @@ extension AnyDispatchQueueScheduler {
238242
if store.contextQueue == .main, Thread.isMainThread {
239243
action()
240244
} else {
241-
store.perform(action)
245+
nonisolated(unsafe) let uncheckedAction = action
246+
store.perform { uncheckedAction() }
242247
}
243248
}
244249

245250
func schedule(options: DispatchQueue.SchedulerOptions?, _ action: @escaping () -> Void) {
246251
if store.contextQueue == .main, Thread.isMainThread {
247252
action()
248253
} else {
249-
store.perform(action)
254+
nonisolated(unsafe) let uncheckedAction = action
255+
store.perform { uncheckedAction() }
250256
}
251257
}
252258
}

EssentialApp/EssentialApp/CommentsUIComposer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Combine
77
import EssentialFeed
88
import EssentialFeediOS
99

10+
@MainActor
1011
public final class CommentsUIComposer {
1112
private init() {}
1213

@@ -38,6 +39,7 @@ public final class CommentsUIComposer {
3839
}
3940
}
4041

42+
@MainActor
4143
final class CommentsViewAdapter: ResourceView {
4244
private weak var controller: ListViewController?
4345

EssentialApp/EssentialApp/FeedUIComposer.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import Combine
77
import EssentialFeed
88
import EssentialFeediOS
99

10+
@MainActor
1011
public final class FeedUIComposer {
1112
private init() {}
1213

1314
private typealias FeedPresentationAdapter = LoadResourcePresentationAdapter<Paginated<FeedImage>, FeedViewAdapter>
1415

1516
public static func feedComposedWith(
16-
feedLoader: @escaping () -> AnyPublisher<Paginated<FeedImage>, Error>,
17-
imageLoader: @escaping (URL) -> FeedImageDataLoader.Publisher,
18-
selection: @escaping (FeedImage) -> Void = { _ in }
17+
feedLoader: @MainActor @escaping () -> AnyPublisher<Paginated<FeedImage>, Error>,
18+
imageLoader: @MainActor @escaping (URL) -> FeedImageDataLoader.Publisher,
19+
selection: @MainActor @escaping (FeedImage) -> Void = { _ in }
1920
) -> ListViewController {
2021
let presentationAdapter = FeedPresentationAdapter(loader: feedLoader)
2122

EssentialApp/EssentialApp/FeedViewAdapter.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import UIKit
66
import EssentialFeed
77
import EssentialFeediOS
88

9+
@MainActor
910
final class FeedViewAdapter: ResourceView {
1011
private weak var controller: ListViewController?
1112
private let imageLoader: (URL) -> FeedImageDataLoader.Publisher

EssentialApp/EssentialApp/LoadResourcePresentationAdapter.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Combine
66
import EssentialFeed
77
import EssentialFeediOS
88

9+
@MainActor
910
final class LoadResourcePresentationAdapter<Resource, View: ResourceView> {
1011
private let loader: () -> AnyPublisher<Resource, Error>
1112
private var cancellable: Cancellable?

EssentialApp/EssentialAppTests/CommentsUIIntegrationTests.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,6 @@ class CommentsUIIntegrationTests: XCTestCase {
108108
assertThat(sut, isRendering: [comment])
109109
}
110110

111-
func test_loadCommentsCompletion_dispatchesFromBackgroundToMainThread() {
112-
let (sut, loader) = makeSUT()
113-
sut.simulateAppearance()
114-
115-
let exp = expectation(description: "Wait for background queue")
116-
DispatchQueue.global().async {
117-
loader.completeCommentsLoading(at: 0)
118-
exp.fulfill()
119-
}
120-
wait(for: [exp], timeout: 1.0)
121-
}
122-
123111
func test_loadCommentsCompletion_rendersErrorMessageOnErrorUntilNextReload() {
124112
let (sut, loader) = makeSUT()
125113

EssentialApp/EssentialAppTests/FeedUIIntegrationTests.swift

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,6 @@ class FeedUIIntegrationTests: XCTestCase {
138138
assertThat(sut, isRendering: [image0])
139139
}
140140

141-
func test_loadFeedCompletion_dispatchesFromBackgroundToMainThread() {
142-
let (sut, loader) = makeSUT()
143-
sut.simulateAppearance()
144-
145-
let exp = expectation(description: "Wait for background queue")
146-
DispatchQueue.global().async {
147-
loader.completeFeedLoading(at: 0)
148-
exp.fulfill()
149-
}
150-
wait(for: [exp], timeout: 1.0)
151-
}
152-
153141
func test_loadFeedCompletion_rendersErrorMessageOnErrorUntilNextReload() {
154142
let (sut, loader) = makeSUT()
155143

@@ -226,20 +214,6 @@ class FeedUIIntegrationTests: XCTestCase {
226214
XCTAssertFalse(sut.isShowingLoadMoreFeedIndicator, "Expected no loading indicator once user initiated loading completes with error")
227215
}
228216

229-
func test_loadMoreCompletion_dispatchesFromBackgroundToMainThread() {
230-
let (sut, loader) = makeSUT()
231-
sut.simulateAppearance()
232-
loader.completeFeedLoading(at: 0)
233-
sut.simulateLoadMoreFeedAction()
234-
235-
let exp = expectation(description: "Wait for background queue")
236-
DispatchQueue.global().async {
237-
loader.completeLoadMore()
238-
exp.fulfill()
239-
}
240-
wait(for: [exp], timeout: 1.0)
241-
}
242-
243217
func test_loadMoreCompletion_rendersErrorMessageOnError() {
244218
let (sut, loader) = makeSUT()
245219
sut.simulateAppearance()
@@ -546,21 +520,6 @@ class FeedUIIntegrationTests: XCTestCase {
546520
XCTAssertNil(view?.renderedImage, "Expected no rendered image when an image load finishes after the view is not visible anymore")
547521
}
548522

549-
func test_loadImageDataCompletion_dispatchesFromBackgroundToMainThread() {
550-
let (sut, loader) = makeSUT()
551-
552-
sut.simulateAppearance()
553-
loader.completeFeedLoading(with: [makeImage()])
554-
_ = sut.simulateFeedImageViewVisible(at: 0)
555-
556-
let exp = expectation(description: "Wait for background queue")
557-
DispatchQueue.global().async {
558-
loader.completeImageLoading(with: self.anyImageData(), at: 0)
559-
exp.fulfill()
560-
}
561-
wait(for: [exp], timeout: 1.0)
562-
}
563-
564523
func test_feedImageView_doesNotLoadImageAgainUntilPreviousRequestCompletes() {
565524
let image = makeImage(url: URL(string: "http://url-0.com")!)
566525
let (sut, loader) = makeSUT()
@@ -590,7 +549,7 @@ class FeedUIIntegrationTests: XCTestCase {
590549
// MARK: - Helpers
591550

592551
private func makeSUT(
593-
selection: @escaping (FeedImage) -> Void = { _ in },
552+
selection: @MainActor @escaping (FeedImage) -> Void = { _ in },
594553
file: StaticString = #filePath,
595554
line: UInt = #line
596555
) -> (sut: ListViewController, loader: LoaderSpy) {

EssentialApp/EssentialAppTests/Helpers/FeedUIIntegrationTests+LoaderSpy.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Combine
99

1010
extension FeedUIIntegrationTests {
1111

12+
@MainActor
1213
class LoaderSpy {
1314

1415
// MARK: - FeedLoader

EssentialApp/EssentialAppTests/Helpers/XCTestCase+MemoryLeakTracking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import XCTest
66

77
extension XCTestCase {
8+
@MainActor
89
func trackForMemoryLeaks(_ instance: AnyObject, file: StaticString = #filePath, line: UInt = #line) {
910
addTeardownBlock { [weak instance] in
1011
XCTAssertNil(instance, "Instance should have been deallocated. Potential memory leak.", file: file, line: line)

0 commit comments

Comments
 (0)