From 22a48e18880afbdd056db265b4ef54d0ea6a33a4 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 18 Mar 2024 17:07:33 +0100 Subject: [PATCH] Created the FeedViewModel view model in the Feed framework and integrated it to the FeedViewController view controller. --- .../Bundle/Sources/Logic/Models/Review.swift | 2 +- .../Logic/View Models/FeedViewModel.swift | 15 +++++++++++++ .../Sources/UI/Components/ReviewCell.swift | 2 +- .../DetailsViewController.swift | 2 +- .../View Controllers/FeedViewController.swift | 21 +++++++++++++++---- Reviews.xcodeproj/project.pbxproj | 4 ++++ 6 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedViewModel.swift diff --git a/Frameworks/Feed/Bundle/Sources/Logic/Models/Review.swift b/Frameworks/Feed/Bundle/Sources/Logic/Models/Review.swift index d83086c..5793335 100644 --- a/Frameworks/Feed/Bundle/Sources/Logic/Models/Review.swift +++ b/Frameworks/Feed/Bundle/Sources/Logic/Models/Review.swift @@ -1,6 +1,6 @@ // // AppDelegate.swift -// AppStoreReviews +// ReviewsFeed // // Created by Dmitrii Ivanov on 21/07/2020. // Copyright © 2020 ING. All rights reserved. diff --git a/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedViewModel.swift b/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedViewModel.swift new file mode 100644 index 0000000..a5a92c9 --- /dev/null +++ b/Frameworks/Feed/Bundle/Sources/Logic/View Models/FeedViewModel.swift @@ -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 { + + } +} diff --git a/Frameworks/Feed/Bundle/Sources/UI/Components/ReviewCell.swift b/Frameworks/Feed/Bundle/Sources/UI/Components/ReviewCell.swift index 3fbaa1f..1d60847 100644 --- a/Frameworks/Feed/Bundle/Sources/UI/Components/ReviewCell.swift +++ b/Frameworks/Feed/Bundle/Sources/UI/Components/ReviewCell.swift @@ -1,6 +1,6 @@ // // AppDelegate.swift -// AppStoreReviews +// ReviewsFeed // // Created by Dmitrii Ivanov on 21/07/2020. // Copyright © 2020 ING. All rights reserved. diff --git a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/DetailsViewController.swift b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/DetailsViewController.swift index 800a7d1..ffe65dc 100644 --- a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/DetailsViewController.swift +++ b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/DetailsViewController.swift @@ -1,6 +1,6 @@ // // AppDelegate.swift -// AppStoreReviews +// ReviewsFeed // // Created by Dmitrii Ivanov on 21/07/2020. // Copyright © 2020 ING. All rights reserved. diff --git a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedViewController.swift b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedViewController.swift index 96db814..f780f01 100644 --- a/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedViewController.swift +++ b/Frameworks/Feed/Bundle/Sources/UI/View Controllers/FeedViewController.swift @@ -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) } + } - diff --git a/Reviews.xcodeproj/project.pbxproj b/Reviews.xcodeproj/project.pbxproj index 927a495..0e46e54 100644 --- a/Reviews.xcodeproj/project.pbxproj +++ b/Reviews.xcodeproj/project.pbxproj @@ -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 = ""; }; 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 = ""; }; 02DC7FB12BA52084000EEEBE /* Libraries */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Libraries; sourceTree = ""; }; @@ -102,6 +104,7 @@ 02620B872BA89C0700DE7137 /* View Models */ = { isa = PBXGroup; children = ( + 02620B8B2BA89C9A00DE7137 /* FeedViewModel.swift */, ); path = "View Models"; sourceTree = ""; @@ -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 */,