Skip to content

Commit ac72fce

Browse files
authored
Merge pull request #22 from engingulek/feature/update-with-concurrency
updated concurreny
2 parents 73a4956 + 67deebe commit ac72fce

10 files changed

Lines changed: 72 additions & 52 deletions

File tree

.DS_Store

2 KB
Binary file not shown.

ICTMDBHomeModule.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380
ONLY_ACTIVE_ARCH = YES;
381381
SDKROOT = iphoneos;
382382
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
383+
SWIFT_DEFAULT_ACTOR_ISOLATION = nonisolated;
383384
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
384385
VERSIONING_SYSTEM = "apple-generic";
385386
VERSION_INFO_PREFIX = "";
@@ -440,6 +441,7 @@
440441
MTL_FAST_MATH = YES;
441442
SDKROOT = iphoneos;
442443
SWIFT_COMPILATION_MODE = wholemodule;
444+
SWIFT_DEFAULT_ACTOR_ISOLATION = nonisolated;
443445
VALIDATE_PRODUCT = YES;
444446
VERSIONING_SYSTEM = "apple-generic";
445447
VERSION_INFO_PREFIX = "";

ICTMDBHomeModule/HomeInteractor.swift

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
import Foundation
99
import ICTMDBNetworkManagerKit
1010

11-
import Foundation
1211

13-
/// `HomeInteractor` handles the data-fetching logic for the Home module.
14-
final class HomeInteractor: @preconcurrency PresenterToInteractorHomeProtocol {
15-
12+
final class HomeInteractor: PresenterToInteractorHomeProtocol {
13+
1614
// MARK: - Properties
1715

1816
/// Reference to the Presenter to send data or errors back.
@@ -24,59 +22,45 @@ final class HomeInteractor: @preconcurrency PresenterToInteractorHomeProtocol {
2422
/// Current device language code (e.g., tr, en).
2523
let deviceLanguageCode = Locale.current.language.languageCode ?? .english
2624

27-
2825
init(network: NetworkManagerProtocol) {
2926
self.network = network
3027
}
3128

3229
// MARK: - Popular TV Shows
3330

34-
/// Loads the list of popular TV shows from the API.
35-
func loadPopularMovies() {
31+
/// Requests popular TV shows data
32+
func loadPopularMovies() async {
3633
let request = PopularMoviesRequest(
3734
language: deviceLanguageCode == .turkish ? .tr : .en,
3835
page: 1
3936
)
40-
41-
// Executes the network request asynchronously.
42-
network.execute(request) { [weak self] result in
43-
guard let self else { return }
44-
45-
switch result {
46-
case .success(let list):
47-
// Sends the fetched popular shows to the Presenter.
48-
presenter?.sendPopularTvShows(list.results)
49-
50-
case .failure:
51-
// Notifies Presenter of an error.
52-
presenter?.sendError(.popular)
53-
}
37+
38+
do {
39+
let list = try await network.execute(request)
40+
presenter?.sendPopularTvShows(list.results)
41+
} catch {
42+
presenter?.sendError(.popular)
5443
}
5544
}
45+
46+
5647

5748
// MARK: - Airing Today TV Shows
5849

59-
/// Loads the list of TV shows airing today.
60-
func loadAiringMovies() {
50+
/// Requests airing today TV shows data
51+
52+
func loadAiringMovies() async {
6153
let request = AiringTodayRequest(
6254
language: deviceLanguageCode == .turkish ? .tr : .en,
6355
page: 1
6456
)
6557

66-
// Executes the network request asynchronously.
67-
network.execute(request) { [weak self] result in
68-
guard let self else { return }
69-
70-
switch result {
71-
case .success(let list):
72-
// Sends the fetched airing shows to the Presenter.
73-
presenter?.sendAiringTvShows(list.results)
74-
75-
case .failure:
76-
// Notifies Presenter of an error.
77-
presenter?.sendError(.airingToday)
78-
}
58+
do {
59+
let list = try await network.execute(request)
60+
presenter?.sendAiringTvShows(list.results)
61+
} catch {
62+
presenter?.sendError(.airingToday)
63+
7964
}
8065
}
8166
}
82-

ICTMDBHomeModule/HomePresenter.swift

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import UIKit
1212

1313
// MARK: - HomePresenter
1414
/// Handles the presentation logic for the Home module.
15+
1516
final class HomePresenter {
1617

1718
// MARK: - Typealias
@@ -50,15 +51,40 @@ final class HomePresenter {
5051

5152
// MARK: - ViewToPresenterHomeProtocol
5253
/// Handles actions triggered by the View layer.
54+
5355
extension HomePresenter: ViewToPresenterHomeProtocol {
54-
56+
5557
func viewDidLoad() {
5658
view?.setBackColorAble(color: "backColor")
5759
//TODO: move to Localizable
5860
view?.setNavigationTitle(title: "Home Page")
59-
interactor.loadPopularMovies()
60-
interactor.loadAiringMovies()
61+
62+
Task {@MainActor in
63+
await loadData()
64+
}
65+
66+
67+
}
68+
69+
70+
71+
@MainActor
72+
func loadData() async {
73+
// Sending 'self' risks causing data races
74+
// Sending main actor-isolated 'self' into async let risks causing data races between nonisolated and main actor-isolated uses
75+
76+
/*
77+
async let popular = interactor.loadPopularMovies()
78+
async let movies = interactor.loadAiringMovies()
79+
await popular
80+
await movies
81+
*/
82+
83+
84+
await interactor.loadPopularMovies()
85+
await interactor.loadAiringMovies()
6186
}
87+
6288
}
6389

6490

@@ -184,7 +210,7 @@ extension HomePresenter {
184210

185211
// MARK: - InteractorToPresenterHomeProtocol
186212
/// Receives data from the Interactor and updates the view.
187-
extension HomePresenter: InteractorToPresenterHomeProtocol {
213+
extension HomePresenter: InteractorToPresenterHomeProtocol {
188214

189215
func sendAiringTvShows(_ data: [AiringToday]) {
190216
view?.startLoading()

ICTMDBHomeModule/HomeProtocols.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typealias Ables = UIViewAble & SegueAble & NavConUIAble
1717

1818
// MARK: - View → Presenter
1919
/// Protocol for communication from View to Presenter.
20+
@MainActor
2021
protocol ViewToPresenterHomeProtocol: AnyObject,
2122
GenericCollectionDataSourceProtocol,
2223
GenericCollectionDelegateSourceProtocol,
@@ -27,6 +28,7 @@ protocol ViewToPresenterHomeProtocol: AnyObject,
2728

2829
/// Called when the view is loaded
2930
func viewDidLoad()
31+
3032
}
3133

3234
// MARK: - Presenter → View
@@ -48,21 +50,23 @@ protocol PresenterToViewHomeProtocol: AnyObject, Ables {
4850

4951
// MARK: - Presenter → Interactor
5052
/// Protocol defining communication from Presenter to Interactor.
51-
protocol PresenterToInteractorHomeProtocol {
52-
53+
@MainActor
54+
protocol PresenterToInteractorHomeProtocol:AnyObject {
55+
5356
/// Reference to the Presenter layer
5457
var presenter: InteractorToPresenterHomeProtocol? { get set }
5558

5659
/// Requests popular TV shows data
57-
func loadPopularMovies()
60+
func loadPopularMovies() async
5861

5962
/// Requests airing today TV shows data
60-
func loadAiringMovies()
63+
func loadAiringMovies() async
6164
}
6265

66+
6367
// MARK: - Interactor → Presenter
6468
/// Protocol for sending data or errors from Interactor to Presenter.
65-
protocol InteractorToPresenterHomeProtocol {
69+
protocol InteractorToPresenterHomeProtocol : AnyObject{
6670

6771
/// Sends fetched popular TV shows
6872
func sendPopularTvShows(_ data: [PopularTvShows])
@@ -76,6 +80,7 @@ protocol InteractorToPresenterHomeProtocol {
7680

7781
// MARK: - Presenter → Router
7882
/// Protocol for navigation actions from Presenter to Router.
83+
7984
protocol PresenterToRouterHomeProtocol {
8085

8186
/// Navigates to All List page

ICTMDBHomeModule/HomeRouter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class HomeRouter: @preconcurrency PresenterToRouterHomeProtocol {
2121
/// - Parameters:
2222
/// - view: The current view conforming to `PresenterToViewHomeProtocol`.
2323
/// - type: The section type (e.g., popular or airingToday).
24-
@MainActor
24+
2525
func toAllListPage(view: PresenterToViewHomeProtocol?, type: SectionType) {
2626
// Determine the list type based on section
2727
let listType: AllListType = type == .popular ? .popular : .airingToday
@@ -41,7 +41,7 @@ public class HomeRouter: @preconcurrency PresenterToRouterHomeProtocol {
4141
/// - Parameters:
4242
/// - view: The current view conforming to `PresenterToViewHomeProtocol`.
4343
/// - id: The TV show ID to display details for.
44-
@MainActor
44+
4545
func toDetailPage(view: (any PresenterToViewHomeProtocol)?, id: Int?) {
4646
// Resolve Detail module dependency from DependencyRegister
4747
// Detail modülünü DependencyRegister üzerinden alır

ICTMDBHomeModule/HomeViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ final class HomeViewController: UIViewController {
4848
setupCollectionView()
4949
collectionPrepareView()
5050
setupUI()
51+
5152
}
5253

5354

ICTMDBHomeModule/requests/AiringTodayRequest.swift

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

1010
//MARK: AiringTodayRequest
1111
struct AiringTodayRequest :NetworkRequest {
12+
1213
typealias Response = DataResult<AiringToday>
1314
var language: RequestLanguage
1415
var page: Int

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import PackageDescription
44
let package = Package(
55
name: "ICTMDBHomeModule",
66
defaultLocalization: "en",
7+
78
platforms: [
8-
.iOS(.v18)
9+
.iOS(.v26)
910
],
1011
products: [
1112
.library(

0 commit comments

Comments
 (0)