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/DI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ protocol AnyCoordinator {
}

protocol RemoteDataSource {
func search(text: String) async throws (BooksViewModelError) -> BookResponse
func search(text: String) async throws(BooksViewModelError) -> BookResponse
}

protocol LocalDataSource: RemoteDataSource {
func save(books: [Book]) async throws (BooksViewModelError)
func save(books: [Book]) async throws(BooksViewModelError)
}

extension Container: @retroactive Then {}
Expand Down
2 changes: 1 addition & 1 deletion Bookie/DI/GoogleRemoteDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import Moya

struct GoogleRemoteDataSource: RemoteDataSource {
func search(text: String) async throws (BooksViewModelError) -> BookResponse {
func search(text: String) async throws(BooksViewModelError) -> BookResponse {
let provider = MoyaProvider<BooksService>(plugins: [
NetworkLoggerPlugin(configuration: .init(
logOptions: [.requestBody, .successResponseBody, .errorResponseBody]
Expand Down
4 changes: 2 additions & 2 deletions Bookie/DI/RealmDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct RealmDataSource: LocalDataSource {
Realm.Configuration.defaultConfiguration.deleteRealmIfMigrationNeeded = true
}

func search(text: String) async throws (BooksViewModelError) -> BookResponse {
func search(text: String) async throws(BooksViewModelError) -> BookResponse {
do {
return try await Task { @MainActor in
let realm = try await Realm()
Expand Down Expand Up @@ -75,7 +75,7 @@ struct RealmDataSource: LocalDataSource {
}
}

func save(books: [Book]) async throws (BooksViewModelError) {
func save(books: [Book]) async throws(BooksViewModelError) {
do {
try await Task { @MainActor in
let realm = try await Realm()
Expand Down
8 changes: 4 additions & 4 deletions Bookie/DI/SwiftDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class BookSwiftData: Identifiable {
actor SwiftDataSource: LocalDataSource {
private var context: ModelContext { modelExecutor.modelContext }

func search(text: String) async throws (BooksViewModelError) -> BookResponse {
func search(text: String) async throws(BooksViewModelError) -> BookResponse {
do {
let books = try context.fetch(FetchDescriptor<BookSwiftData>()).map {
Book(
Expand Down Expand Up @@ -61,10 +61,10 @@ actor SwiftDataSource: LocalDataSource {
}
}

func save(books: [Book]) async throws (BooksViewModelError) {
func save(books: [Book]) async throws(BooksViewModelError) {
do {
books.forEach {
context.insert(BookSwiftData(id: $0.id, title: $0.volumeInfo.title))
for book in books {
context.insert(BookSwiftData(id: book.id, title: book.volumeInfo.title))
}
try context.save()
} catch {
Expand Down
4 changes: 2 additions & 2 deletions Bookie/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import UIKit

extension Optional {
func mapAsync<E, U>(
_ transform: @Sendable (Wrapped) async throws (E) -> U
) async throws (E) -> U? where E: Error, U: ~Copyable {
_ transform: @Sendable (Wrapped) async throws(E) -> U
) async throws(E) -> U? where E: Error, U: ~Copyable {
if let self {
return try await transform(self)
} else {
Expand Down
6 changes: 3 additions & 3 deletions Bookie/UI/BooksScreenSwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ struct BooksScreenRootView: View {
VStack {
HStack {
TextField("", text: $searchText, onEditingChanged: { _ in
self.showCancelButton = true
showCancelButton = true
}, onCommit: {})
.padding(.leading, LayoutParams.BooksScren.defaultInset)
.foregroundStyle(Color(AppColors.textColor))
if showCancelButton {
Button(L10n.BooksScreen.Button.cancel) {
self.searchText = ""
self.showCancelButton = false
searchText = ""
showCancelButton = false
}
.foregroundStyle(Color(AppColors.textColor))
.padding(.trailing, LayoutParams.BooksScren.defaultInset)
Expand Down
2 changes: 1 addition & 1 deletion Bookie/UI/MainStylesheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Fashion
import UIKit

struct LayoutParams {
enum LayoutParams {
enum BooksScren {
static let defaultInset = CGFloat(20)
static let smallerInset = CGFloat(10)
Expand Down
6 changes: 4 additions & 2 deletions Bookie/ViewModel/BooksViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ final class BooksViewModel<BooksScreenType: AnyObject & AnyBooksScreen>: BasicVi
self.screen = screen
}

func reloadData() async {
override func reloadData() async {
await super.reloadData()
guard let source = dependenciesContainer.resolve(RemoteDataSource.self),
let localSource = dependenciesContainer.resolve(LocalDataSource.self)
else {
Expand All @@ -83,7 +84,8 @@ final class BooksViewModel<BooksScreenType: AnyObject & AnyBooksScreen>: BasicVi
}
}

func ready() {
override func ready() {
super.ready()
searchText.removeDuplicates().sink { [weak screen = self.screen] text in
_Concurrency.Task { [weak screen] in
await screen?.onSearchTextChanged(text)
Expand Down
2 changes: 1 addition & 1 deletion BookieTests/BookieTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class BookieTests: XCTestCase {
private struct TestRemoteDataSource: RemoteDataSource {
let expected: [Book]

func search(text _: String) async throws (BooksViewModelError) -> BookResponse {
func search(text _: String) async throws(BooksViewModelError) -> BookResponse {
.init(
kind: "",
totalItems: expected.count,
Expand Down
4 changes: 2 additions & 2 deletions Mintfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
yonaskolb/[email protected]
realm/swiftlint@0.58.2
nicklockwood/swiftformat@0.49.1
realm/swiftlint@0.59.1
nicklockwood/swiftformat@0.56.2
swiftgen/[email protected]
Binary file added Screenshot/detail_uikit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshot/main_uikit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ packages:
version: 2.2.1
OrderedCollections:
url: https://github.com/apple/swift-collections
version: 1.1.4
version: 1.2.0
JobInterviewAssignmentKit:
url: https://github.com/RomanPodymov/JobInterviewAssignmentKit
version: 0.0.1
version: 0.0.2
RealmSwift:
url: https://github.com/realm/realm-swift.git
version: 20.0.2
Expand Down