Skip to content

Commit ed75d0f

Browse files
committed
List issue fixes
1 parent 3453b4b commit ed75d0f

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

Chapter 14/MyProjectClient/iOS/Sources/Modules/Root/RootEntity.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ struct RootEntity {
1313
struct Item {
1414
let id: UUID
1515
let title: String
16-
let imageUrl: String
17-
let url: String
16+
let imageUrl: URL
17+
let url: URL
1818
}
1919

2020
let items: [Item]

Chapter 14/MyProjectClient/iOS/Sources/Modules/Root/RootInteractor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ extension RootInteractor: RootInteractorPresenterInterface {
2222
let domain = "http://localhost:8080"
2323
return .init(items: page.items.map { .init(id: $0.id,
2424
title: $0.title,
25-
imageUrl: domain + $0.image,
26-
url: domain + $0.slug) })
25+
imageUrl: URL(string: domain + $0.image)!,
26+
url: URL(string: domain + "/" + $0.slug)!) })
2727
}
2828
.mapError { $0 as Error }
2929
.eraseToAnyPublisher()

Chapter 14/MyProjectClient/iOS/Sources/Modules/Root/RootView.swift

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ final class RootView: UIViewController, ViewInterface {
8282
@objc func refresh() {
8383
self.presenter.reload()
8484
}
85-
8685
}
8786

8887
extension RootView: RootViewPresenterInterface {
@@ -113,7 +112,6 @@ extension RootView: RootViewPresenterInterface {
113112
}
114113
}
115114

116-
117115
extension RootView: UITableViewDataSource {
118116

119117
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
@@ -124,16 +122,15 @@ extension RootView: UITableViewDataSource {
124122
let item = self.entity!.items[indexPath.row]
125123
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomCell
126124

125+
let defaultImage = UIImage(named: "Default")!
127126
cell.titleLabel.text = item.title
128-
cell.coverView.image = UIImage(named: "Default")
129-
130-
let url = URL(string: "http://localhost:8080" + item.imageUrl)!
127+
cell.coverView.image = defaultImage
131128

132129
self.operations["cell-\(indexPath.row)"]?.cancel()
133130
self.operations["cell-\(indexPath.row)"] = URLSession.shared
134-
.downloadTaskPublisher(for: url)
135-
.map { UIImage(contentsOfFile: $0.url.path) ?? UIImage(named: "Default") }
136-
.replaceError(with: UIImage(named: "Default"))
131+
.downloadTaskPublisher(for: item.imageUrl)
132+
.map { UIImage(contentsOfFile: $0.url.path) ?? defaultImage }
133+
.replaceError(with: defaultImage)
137134
.receive(on: DispatchQueue.main)
138135
.assign(to: \.image, on: cell.coverView)
139136

@@ -151,15 +148,10 @@ extension RootView: UITableViewDelegate {
151148
tableView.deselectRow(at: indexPath, animated: true)
152149

153150
let item = self.entity!.items[indexPath.row]
154-
155-
let urlString = "http://localhost:8080/" + item.url
156-
157-
if let url = URL(string: urlString) {
158-
let vc = SFSafariViewController(url: url)
159-
vc.modalPresentationStyle = .overFullScreen
160-
vc.delegate = self
161-
present(vc, animated: true)
162-
}
151+
let vc = SFSafariViewController(url: item.url)
152+
vc.modalPresentationStyle = .overFullScreen
153+
vc.delegate = self
154+
present(vc, animated: true)
163155
}
164156
}
165157

0 commit comments

Comments
 (0)