From 1842440c820fb01727230fbaeda6ffa1ce7fb924 Mon Sep 17 00:00:00 2001 From: swg99 <87419041+swg99@users.noreply.github.com> Date: Wed, 28 Jul 2021 13:59:07 +0100 Subject: [PATCH 1/3] Created ContentView to replace TabViewController --- .../Rick And Morty.xcodeproj/project.pbxproj | 12 +++++--- .../Rick And Morty/Views/ContentView.swift | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 Rick-and-Morty/Rick And Morty/Views/ContentView.swift diff --git a/Rick-and-Morty/Rick And Morty.xcodeproj/project.pbxproj b/Rick-and-Morty/Rick And Morty.xcodeproj/project.pbxproj index f0b45a2..d9e8e64 100644 --- a/Rick-and-Morty/Rick And Morty.xcodeproj/project.pbxproj +++ b/Rick-and-Morty/Rick And Morty.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 1711B39C26B16D6200BE935B /* CharactersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1711B39B26B16D6200BE935B /* CharactersView.swift */; }; + 1711B39E26B1898100BE935B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1711B39D26B1898100BE935B /* ContentView.swift */; }; 17CAB4FA26A824470048F2F1 /* CharacterCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17CAB4F926A824470048F2F1 /* CharacterCell.swift */; }; 17F1E38226A18A54009C1CDB /* CharacterCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F1E38126A18A54009C1CDB /* CharacterCollectionViewController.swift */; }; 17F1E38426A18EA8009C1CDB /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F1E38326A18EA8009C1CDB /* TabBarController.swift */; }; @@ -35,6 +36,7 @@ /* Begin PBXFileReference section */ 1711B39B26B16D6200BE935B /* CharactersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CharactersView.swift; sourceTree = ""; }; + 1711B39D26B1898100BE935B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 17CAB4F926A824470048F2F1 /* CharacterCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CharacterCell.swift; sourceTree = ""; }; 17F1E38126A18A54009C1CDB /* CharacterCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CharacterCollectionViewController.swift; sourceTree = ""; }; 17F1E38326A18EA8009C1CDB /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = ""; }; @@ -98,6 +100,7 @@ 17F1E38926A1D877009C1CDB /* CharacterCollectionViewCell.swift */, 17CAB4F926A824470048F2F1 /* CharacterCell.swift */, 1711B39B26B16D6200BE935B /* CharactersView.swift */, + 1711B39D26B1898100BE935B /* ContentView.swift */, ); path = Views; sourceTree = ""; @@ -250,6 +253,7 @@ buildActionMask = 2147483647; files = ( 17F1E38D26A1DCF0009C1CDB /* Data.swift in Sources */, + 1711B39E26B1898100BE935B /* ContentView.swift in Sources */, B811686D1CFF1C9900301A0A /* AppDelegate.swift in Sources */, 17F1E38226A18A54009C1CDB /* CharacterCollectionViewController.swift in Sources */, 17CAB4FA26A824470048F2F1 /* CharacterCell.swift in Sources */, @@ -348,7 +352,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -398,7 +402,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; @@ -414,7 +418,7 @@ CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "Rick And Morty/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.novoda.Rick-And-Morty"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -432,7 +436,7 @@ CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "Rick And Morty/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.novoda.Rick-And-Morty"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Rick-and-Morty/Rick And Morty/Views/ContentView.swift b/Rick-and-Morty/Rick And Morty/Views/ContentView.swift new file mode 100644 index 0000000..7c0972f --- /dev/null +++ b/Rick-and-Morty/Rick And Morty/Views/ContentView.swift @@ -0,0 +1,30 @@ +// +// ContentView.swift +// Rick And Morty +// +// Created by Scottie Gray on 2021-07-28. +// Copyright © 2021 Novoda. All rights reserved. +// + +import SwiftUI + +struct ContentView: View { + var body: some View { + TabView { + CharactersView(characters: ricks, title: "Ricks") + .tabItem { + Label("Ricks", image: "rick-icon") + } + CharactersView(characters: morties, title: "Morties") + .tabItem { + Label("Morties", image: "morty-icon") + } + } + } +} + +struct ContentView_Previews: PreviewProvider { + static var previews: some View { + ContentView() + } +} From affc9f8980e9cd8a9548f6f47a64ab31aec6bba0 Mon Sep 17 00:00:00 2001 From: swg99 <87419041+swg99@users.noreply.github.com> Date: Wed, 28 Jul 2021 14:08:22 +0100 Subject: [PATCH 2/3] Edited AppDelegate to use ContentView --- Rick-and-Morty/Rick And Morty/AppDelegate.swift | 13 +++++++------ .../Rick And Morty/Views/ContentView.swift | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Rick-and-Morty/Rick And Morty/AppDelegate.swift b/Rick-and-Morty/Rick And Morty/AppDelegate.swift index 31619e2..4bc13f8 100644 --- a/Rick-and-Morty/Rick And Morty/AppDelegate.swift +++ b/Rick-and-Morty/Rick And Morty/AppDelegate.swift @@ -1,10 +1,11 @@ import UIKit +import SwiftUI -@UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate { - var window: UIWindow? - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - return true +@main +struct RickAndMorty: App { + var body: some Scene { + WindowGroup { + ContentView() + } } } diff --git a/Rick-and-Morty/Rick And Morty/Views/ContentView.swift b/Rick-and-Morty/Rick And Morty/Views/ContentView.swift index 7c0972f..3501bbe 100644 --- a/Rick-and-Morty/Rick And Morty/Views/ContentView.swift +++ b/Rick-and-Morty/Rick And Morty/Views/ContentView.swift @@ -9,6 +9,7 @@ import SwiftUI struct ContentView: View { + var body: some View { TabView { CharactersView(characters: ricks, title: "Ricks") From 398d5c31f2d2dc54c42838c52c8190458085e27d Mon Sep 17 00:00:00 2001 From: swg99 <87419041+swg99@users.noreply.github.com> Date: Wed, 28 Jul 2021 14:13:11 +0100 Subject: [PATCH 3/3] Removed ViewControllers --- .DS_Store | Bin 8196 -> 8196 bytes .../Rick And Morty.xcodeproj/project.pbxproj | 16 ------- .../CharacterCollectionViewController.swift | 44 ------------------ .../ViewControllers/TabBarController.swift | 16 ------- 4 files changed, 76 deletions(-) delete mode 100644 Rick-and-Morty/Rick And Morty/ViewControllers/CharacterCollectionViewController.swift delete mode 100644 Rick-and-Morty/Rick And Morty/ViewControllers/TabBarController.swift diff --git a/.DS_Store b/.DS_Store index 9189fc554fd2419b5afc43a8166ebbc873273c87..dcbfa2d67d5e322e4bf51f732066af6e85a0e0db 100644 GIT binary patch delta 79 zcmV-V0I>grK!iZB+YMKsGB+$BGBG%PEFgP1GB7M4G&44ReF+E`B{4lo lU~PGNdwhLPHSYh)K5hv!&>=M6NHi Int { - return characters.count - } - - override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CharacterCollectionViewCell.reuseIdentifier, for:indexPath) - guard let characterCell = cell as? CharacterCollectionViewCell else { - return cell - } - - let character = characters[indexPath.row] - let imagePosition = getImagePosition(character: character) - - characterCell.embed(in: self, withCharacter: character, imagePosition: imagePosition) - - return characterCell - } - - private func getImagePosition(character: Character) -> CharacterImagePosition { - if character is Morty { - return .left - } - else { - return .right - } - } -} diff --git a/Rick-and-Morty/Rick And Morty/ViewControllers/TabBarController.swift b/Rick-and-Morty/Rick And Morty/ViewControllers/TabBarController.swift deleted file mode 100644 index 4dbc3ea..0000000 --- a/Rick-and-Morty/Rick And Morty/ViewControllers/TabBarController.swift +++ /dev/null @@ -1,16 +0,0 @@ -import UIKit -import SwiftUI - -class TabBarController: UITabBarController, UITabBarControllerDelegate { - - override func viewDidLoad() { - - let rickViewController = UIHostingController(rootView: CharactersView(characters: ricks, title: "Ricks")) - rickViewController.tabBarItem = UITabBarItem(title: "Ricks", image: UIImage(named: "rick-icon"), tag: 1) - - let mortyViewController = UIHostingController(rootView: CharactersView(characters: morties, title: "Morties")) - mortyViewController.tabBarItem = UITabBarItem(title: "Morties", image: UIImage(named: "morty-icon"), tag: 2) - - self.setViewControllers([rickViewController, mortyViewController], animated: false) - } -}