Created the FeedViewModel view model in the Feed framework and integrated it to the FeedViewController view controller.

This commit is contained in:
Javier Cicchelli 2024-03-18 17:07:33 +01:00
parent 24600daefa
commit 22a48e1888
6 changed files with 39 additions and 7 deletions

View File

@ -1,6 +1,6 @@
//
// AppDelegate.swift
// AppStoreReviews
// ReviewsFeed
//
// Created by Dmitrii Ivanov on 21/07/2020.
// Copyright © 2020 ING. All rights reserved.

View File

@ -0,0 +1,15 @@
//
// FeedViewModel.swift
// ReviewsFeed
//
// Created by Javier Cicchelli on 18/03/2024.
// Copyright © 2024 Röck+Cöde. All rights reserved.
//
import Foundation
extension FeedViewController {
final class ViewModel: ObservableObject {
}
}

View File

@ -1,6 +1,6 @@
//
// AppDelegate.swift
// AppStoreReviews
// ReviewsFeed
//
// Created by Dmitrii Ivanov on 21/07/2020.
// Copyright © 2020 ING. All rights reserved.

View File

@ -1,6 +1,6 @@
//
// AppDelegate.swift
// AppStoreReviews
// ReviewsFeed
//
// Created by Dmitrii Ivanov on 21/07/2020.
// Copyright © 2020 ING. All rights reserved.

View File

@ -1,6 +1,6 @@
//
// AppDelegate.swift
// AppStoreReviews
// ReviewsFeed
//
// Created by Dmitrii Ivanov on 21/07/2020.
// Copyright © 2020 ING. All rights reserved.
@ -10,6 +10,10 @@ import UIKit
public class FeedViewController: UITableViewController {
// MARK: Constants
private let viewModel: ViewModel = .init()
// MARK: Initialisers
public init() {
super.init(style: .plain)
}
@ -18,28 +22,37 @@ public class FeedViewController: UITableViewController {
fatalError("init(coder:) has not been implemented")
}
// MARK: UIViewController
public override func viewDidLoad() {
super.viewDidLoad()
tableView.register(ReviewCell.self, forCellReuseIdentifier: "cellId")
tableView.rowHeight = 160
}
// MARK: UITableViewDataSource
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let c = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! ReviewCell
c.update(item: randomReview())
return c
}
// MARK: UITableViewDelegate
public override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let vc = DetailsViewController(review: randomReview())
navigationController!.pushViewController(vc, animated: true)
}
}
// MARK: - Helpers
private extension FeedViewController {
// MARK: Functions
func randomReview() -> Review {
let author = ["Dan Auerbach", "Bo Diddley", "Otis Rush", "Jimi Hendrix", "Albert King", "Buddy Guy", "Muddy Waters", "Eric Clapton"].randomElement()!
let version = ["3.11", "3.12"].randomElement()!
@ -54,5 +67,5 @@ public class FeedViewController: UITableViewController {
id: id,
content: content)
}
}

View File

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
02620B8C2BA89C9A00DE7137 /* FeedViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02620B8B2BA89C9A00DE7137 /* FeedViewModel.swift */; };
02DC7F9F2BA51793000EEEBE /* ReviewsFeed.h in Headers */ = {isa = PBXBuildFile; fileRef = 02DC7F912BA51793000EEEBE /* ReviewsFeed.h */; settings = {ATTRIBUTES = (Public, ); }; };
02DC7FA22BA51793000EEEBE /* ReviewsFeed.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02DC7F8F2BA51793000EEEBE /* ReviewsFeed.framework */; };
02DC7FA32BA51793000EEEBE /* ReviewsFeed.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 02DC7F8F2BA51793000EEEBE /* ReviewsFeed.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@ -46,6 +47,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
02620B8B2BA89C9A00DE7137 /* FeedViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedViewModel.swift; sourceTree = "<group>"; };
02DC7F8F2BA51793000EEEBE /* ReviewsFeed.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ReviewsFeed.framework; sourceTree = BUILT_PRODUCTS_DIR; };
02DC7F912BA51793000EEEBE /* ReviewsFeed.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReviewsFeed.h; sourceTree = "<group>"; };
02DC7FB12BA52084000EEEBE /* Libraries */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Libraries; sourceTree = "<group>"; };
@ -102,6 +104,7 @@
02620B872BA89C0700DE7137 /* View Models */ = {
isa = PBXGroup;
children = (
02620B8B2BA89C9A00DE7137 /* FeedViewModel.swift */,
);
path = "View Models";
sourceTree = "<group>";
@ -362,6 +365,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
02620B8C2BA89C9A00DE7137 /* FeedViewModel.swift in Sources */,
02DC7FAC2BA51B4C000EEEBE /* DetailsViewController.swift in Sources */,
02DC7FAF2BA51B4C000EEEBE /* Review.swift in Sources */,
02DC7FAE2BA51B4C000EEEBE /* FeedViewController.swift in Sources */,