Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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 Bookie/DI/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class Coordinator: AnyCoordinator {
class func createRootScreen(
searchText: String,
previousBook: Book?
) -> (AnyBooksScreen & UIViewController) {
) -> (any AnyBooksScreen & UIViewController) {
BooksScreen(searchText: searchText, previousBook: previousBook)
}

@MainActor
class func createDetailScreen(
_ data: Book
) -> (AnyBookScreen & UIViewController) {
) -> (any AnyBookScreen & UIViewController) {
BookScreen(data)
}

Expand Down
4 changes: 2 additions & 2 deletions Bookie/DI/CoordinatorSwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class CoordinatorSwiftUI: Coordinator {
override class func createRootScreen(
searchText: String,
previousBook: Book?
) -> (AnyBooksScreen & UIViewController) {
) -> (any AnyBooksScreen & UIViewController) {
BooksScreenSwiftUI(searchText: searchText, previousBook: previousBook)
}

@MainActor
override class func createDetailScreen(
_ data: Book
) -> (AnyBookScreen & UIViewController) {
) -> (any AnyBookScreen & UIViewController) {
BookScreenSwiftUI(data)
}
}
2 changes: 1 addition & 1 deletion Bookie/DI/DI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extension Container: @retroactive Then {}
let dependenciesContainer = Container().then { result in
let objectScope: ObjectScope = .container
result.register(AnyCoordinator.self) { _ in
CoordinatorSwiftUI()
Coordinator()
}.inObjectScope(objectScope)
result.register(Stylesheet.self) { _ in
MainStylesheet()
Expand Down
2 changes: 1 addition & 1 deletion Bookie/UI/BookScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class BookScreen: UIViewController {
private unowned var bookImage: UIImageView!
private unowned var metadataRootView: UIView!

private var viewModel: BookViewModel!
var viewModel: BookViewModel<BookScreen>!

init(_ data: Book?) {
super.init(nibName: nil, bundle: nil)
Expand Down
4 changes: 2 additions & 2 deletions Bookie/UI/BookScreenSwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct BookScreenRootView: View {
}

final class BookScreenSwiftUI: UIHostingController<BookScreenRootView>, AnyBookScreen {
private var viewModel: BookViewModel!
var viewModel: BookViewModel<BookScreenSwiftUI>!

init(_ data: Book?) {
viewModel = BookViewModel(screen: nil, data: data)
Expand All @@ -73,7 +73,7 @@ final class BookScreenSwiftUI: UIHostingController<BookScreenRootView>, AnyBookS
nil
}

private static func backPressedBinding(viewModel: BookViewModel) -> Binding<Bool> {
private static func backPressedBinding(viewModel: BookViewModel<BookScreenSwiftUI>) -> Binding<Bool> {
.init(get: {
false
}, set: { _ in
Expand Down
2 changes: 1 addition & 1 deletion Bookie/UI/BooksScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class BooksScreen: UIViewController {
private unowned var rootView: UICollectionView!
private unowned var loadingView: LoadingView!

private var viewModel: BooksViewModel!
var viewModel: BooksViewModel<BooksScreen>!

init(searchText: String, previousBook: Book?) {
super.init(nibName: nil, bundle: nil)
Expand Down
6 changes: 3 additions & 3 deletions Bookie/UI/BooksScreenSwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct BooksScreenRootView: View {
}

final class BooksScreenSwiftUI: UIHostingController<BooksScreenRootView>, AnyBooksScreen {
private var viewModel: BooksViewModel!
var viewModel: BooksViewModel<BooksScreenSwiftUI>!
Copy link

Copilot AI May 14, 2025

Choose a reason for hiding this comment

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

[nitpick] Changing the viewModel from private to internal exposes it beyond the class; consider whether this exposure is intentional or if encapsulation should be maintained.

Suggested change
var viewModel: BooksViewModel<BooksScreenSwiftUI>!
private var viewModel: BooksViewModel<BooksScreenSwiftUI>!

Copilot uses AI. Check for mistakes.

init(searchText: String, previousBook: Book?) {
viewModel = .init(screen: nil, searchText: searchText, previousBook: previousBook)
Expand All @@ -96,7 +96,7 @@ final class BooksScreenSwiftUI: UIHostingController<BooksScreenRootView>, AnyBoo

private static func selectedBook(
previousBook: Book?,
viewModel: BooksViewModel
viewModel: BooksViewModel<BooksScreenSwiftUI>
) -> Binding<Book?> {
.init(get: {
previousBook
Expand All @@ -112,7 +112,7 @@ final class BooksScreenSwiftUI: UIHostingController<BooksScreenRootView>, AnyBoo
})
}

private static func searchTextBinding(viewModel: BooksViewModel) -> Binding<String> {
private static func searchTextBinding(viewModel: BooksViewModel<BooksScreenSwiftUI>) -> Binding<String> {
.init(get: { [weak viewModel] in
viewModel?.searchText.value ?? ""
}, set: { [weak viewModel] in
Expand Down
12 changes: 6 additions & 6 deletions Bookie/ViewModel/BookViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
// Copyright © 2025 Bookie. All rights reserved.
//

import JobInterviewAssignmentKit
import UIKit

protocol AnyBookScreen: AnyObject {
protocol AnyBookScreen: Screen {
@MainActor
init(_ data: Book?)
}

class BookViewModel {
unowned var screen: AnyBookScreen!

class BookViewModel<BookScreenType: AnyObject & AnyBookScreen>: BasicViewModel<BookScreenType> {
var data: Book?

init(screen: AnyBookScreen!, data: Book? = nil) {
self.screen = screen
init(screen: BookScreenType!, data: Book? = nil) {
self.data = data
super.init()
self.screen = screen
}

@MainActor
Expand Down
12 changes: 6 additions & 6 deletions Bookie/ViewModel/BooksViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import Combine
import CombineMoya
import DifferenceKit
import Foundation
import JobInterviewAssignmentKit
import Moya
import OrderedCollections

protocol AnyBooksScreen: AnyObject, Sendable {
protocol AnyBooksScreen: Screen, Sendable {
@MainActor
init(searchText: String, previousBook: Book?)
func onNewDataReceived(oldSet: DataSetType, newSet: DataSetType) async
Expand All @@ -40,9 +41,7 @@ enum BooksViewModelError: Error {
case requestError(Error)
}

final class BooksViewModel {
unowned var screen: AnyBooksScreen!

final class BooksViewModel<BooksScreenType: AnyObject & AnyBooksScreen>: BasicViewModel<BooksScreenType> {
let searchText: CurrentValueSubject<String, Never>
var previousBook: Book?

Expand All @@ -52,11 +51,12 @@ final class BooksViewModel {
private var newSet: DataSetType = .init()
private var cancellables = Set<AnyCancellable>()

init(screen: AnyBooksScreen!, searchText: String, previousBook: Book?, data: BookResponse? = nil) {
self.screen = screen
init(screen: BooksScreenType!, searchText: String, previousBook: Book?, data: BookResponse? = nil) {
self.searchText = .init(searchText)
self.previousBook = previousBook
self.data = data
super.init()
self.screen = screen
}

func reloadData() async {
Expand Down
9 changes: 6 additions & 3 deletions BookieTests/BookieTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ extension Book: @retroactive Equatable {
}

private final class TestScreen: AnyBooksScreen {
var viewModel: BooksViewModel<TestScreen>!

@MainActor
var testCheck: (@Sendable (DataSetType) -> Void)!

required init(searchText _: String, previousBook _: Book?) {}
required init(searchText: String, previousBook: Book?) {
viewModel = BooksViewModel(screen: self, searchText: searchText, previousBook: previousBook)
}

func onNewDataReceived(oldSet _: DataSetType, newSet: DataSetType) async {
await testCheck(newSet)
Expand Down Expand Up @@ -91,8 +95,7 @@ class BookieTests: XCTestCase {
}

// When
let viewModel = BooksViewModel(screen: screen, searchText: "", previousBook: nil)
await viewModel.reloadData()
await screen.viewModel.reloadData()
}
}

Expand Down
11 changes: 8 additions & 3 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ packages:
OrderedCollections:
url: https://github.com/apple/swift-collections
version: 1.1.4
JobInterviewAssignmentKit:
url: https://github.com/RomanPodymov/JobInterviewAssignmentKit
version: 0.0.1
RealmSwift:
url: https://github.com/realm/realm-swift.git
version: 20.0.2
Expand All @@ -70,6 +73,7 @@ targets:
- package: UICollectionViewLeftAlignedLayout
- package: SwiftAlertView
- package: OrderedCollections
- package: JobInterviewAssignmentKit
- package: RealmSwift
embed: true
info:
Expand All @@ -78,17 +82,18 @@ targets:
NSAppTransportSecurity:
NSAllowsArbitraryLoads: YES
preBuildScripts:
- script: "mint run swiftgen"
- script: "/opt/homebrew/bin/mint run swiftgen"
name: SwiftGen
postCompileScripts:
- script: "mint run swiftformat . --swiftversion 5.5"
- script: "/opt/homebrew/bin/mint run swiftformat . --swiftversion 5.5"
name: SwiftFormat
- script: "mint run swiftlint"
- script: "/opt/homebrew/bin/mint run swiftlint"
Comment on lines +85 to +90
Copy link

Copilot AI May 14, 2025

Choose a reason for hiding this comment

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

[nitpick] The use of absolute paths for mint commands can improve reliability; ensure that these paths are consistent across different environments.

Copilot uses AI. Check for mistakes.
name: SwiftLint
BookieAppTests:
settings:
base:
SWIFT_VERSION: 6
SWIFT_ACTIVE_COMPILATION_CONDITIONS: ${SWIFT_ACTIVE_COMPILATION_CONDITIONS}
type: bundle.unit-test
platform: iOS
sources: [BookieTests]
Expand Down