From e42843957660e04d8acbadb4812445bc5a29a446 Mon Sep 17 00:00:00 2001 From: Elias Ferreira Date: Thu, 30 Dec 2021 22:20:47 -0300 Subject: [PATCH 1/3] Remove force unwrap on TabBarController --- memo/UI/ViewControllers/TabBarController.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/memo/UI/ViewControllers/TabBarController.swift b/memo/UI/ViewControllers/TabBarController.swift index e6ff7b0..926b598 100644 --- a/memo/UI/ViewControllers/TabBarController.swift +++ b/memo/UI/ViewControllers/TabBarController.swift @@ -44,11 +44,17 @@ class TabBarController: UITabBarController { } private func getControllers() -> [UINavigationController] { - return [ - collectionsNavController!, - searchNavController!, - settingsNavController! - ] + if let collecNC = collectionsNavController, + let searchNC = searchNavController, + let settingsNC = settingsNavController { + return [ + collecNC, + searchNC, + settingsNC + ] + } else { + return [] + } } private func configTabBar() { From 12af70f9f81ff43804f4d4a103316aee57e3c8d0 Mon Sep 17 00:00:00 2001 From: Elias Ferreira Date: Thu, 30 Dec 2021 22:44:48 -0300 Subject: [PATCH 2/3] Start UIImage extension --- memo.xcodeproj/project.pbxproj | 6 ++++- .../Contents.json | 0 .../folder_tab.png | Bin .../folder_tab@2x.png | Bin .../folder_tab@3x.png | Bin .../Contents.json | 0 .../folder_unselected.png | Bin .../folder_unselected@2x.png | Bin .../folder_unselected@3x.png | Bin .../Contents.json | 0 .../search.png | Bin .../search@2x.png | Bin .../search@3x.png | Bin .../Contents.json | 0 .../settings.png | Bin .../settings@2x.png | Bin .../settings@3x.png | Bin memo/Extensions/UIImage.swift | 21 ++++++++++++++++++ .../SearchViewController.swift | 6 ++--- .../UI/ViewControllers/TabBarController.swift | 12 +++++----- 20 files changed, 35 insertions(+), 10 deletions(-) rename memo/Assets/Assets.xcassets/tabbar_icons/{foldert.imageset => folder_selected.imageset}/Contents.json (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{foldert.imageset => folder_selected.imageset}/folder_tab.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{foldert.imageset => folder_selected.imageset}/folder_tab@2x.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{foldert.imageset => folder_selected.imageset}/folder_tab@3x.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{foldert_unselected.imageset => folder_unselected.imageset}/Contents.json (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{foldert_unselected.imageset => folder_unselected.imageset}/folder_unselected.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{foldert_unselected.imageset => folder_unselected.imageset}/folder_unselected@2x.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{foldert_unselected.imageset => folder_unselected.imageset}/folder_unselected@3x.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{search.imageset => search_selected.imageset}/Contents.json (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{search.imageset => search_selected.imageset}/search.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{search.imageset => search_selected.imageset}/search@2x.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{search.imageset => search_selected.imageset}/search@3x.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{settings.imageset => settings_selected.imageset}/Contents.json (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{settings.imageset => settings_selected.imageset}/settings.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{settings.imageset => settings_selected.imageset}/settings@2x.png (100%) rename memo/Assets/Assets.xcassets/tabbar_icons/{settings.imageset => settings_selected.imageset}/settings@3x.png (100%) create mode 100644 memo/Extensions/UIImage.swift diff --git a/memo.xcodeproj/project.pbxproj b/memo.xcodeproj/project.pbxproj index ac6650e..3f5bba3 100644 --- a/memo.xcodeproj/project.pbxproj +++ b/memo.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 15812045C326C23E345921DD /* Pods_memoTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04EEBA60473CE4DCD2585AEF /* Pods_memoTests.framework */; }; 92C59443D5FA015A965D98AE /* Pods_memo_memoUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6148FCCBAE7E3C1A76B730A /* Pods_memo_memoUITests.framework */; }; A0D08A94BB5D27A55BDAB679 /* Pods_memo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9879A24529828D8673024C79 /* Pods_memo.framework */; }; + DE1948C3277E958B0027AFC1 /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE1948C2277E958B0027AFC1 /* UIImage.swift */; }; DE4428D12546FBC200A8657C /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE4428D02546FBC200A8657C /* TabBarController.swift */; }; DE4428D62547017100A8657C /* CollectionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE4428D52547017100A8657C /* CollectionsView.swift */; }; DE4428F22547238200A8657C /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE4428F12547238200A8657C /* SettingsViewController.swift */; }; @@ -119,6 +120,7 @@ 9879A24529828D8673024C79 /* Pods_memo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_memo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9E29D5D1FCC75D4DF71D5878 /* Pods-memo-memoUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-memo-memoUITests.debug.xcconfig"; path = "Target Support Files/Pods-memo-memoUITests/Pods-memo-memoUITests.debug.xcconfig"; sourceTree = ""; }; B6148FCCBAE7E3C1A76B730A /* Pods_memo_memoUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_memo_memoUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + DE1948C2277E958B0027AFC1 /* UIImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = ""; }; DE4428D02546FBC200A8657C /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = ""; }; DE4428D52547017100A8657C /* CollectionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionsView.swift; sourceTree = ""; }; DE4428F12547238200A8657C /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; @@ -389,10 +391,10 @@ DE8779582630AA0100C6B68E /* Assets */ = { isa = PBXGroup; children = ( + DEF04A6D24EAC9F1003457F2 /* Fonts */, DE7D997125D391E10053679C /* Assets.xcassets */, DE8A0D1127079DC4003751F0 /* Localizable.strings */, DE8A0D1327079DFC003751F0 /* Strings.swift */, - DEF04A6D24EAC9F1003457F2 /* Fonts */, ); path = Assets; sourceTree = ""; @@ -477,6 +479,7 @@ DE8E82CA2548A9050067899B /* UITextField.swift */, DEEC9DE226000E67005259C0 /* UIImageView.swift */, DE8779532630A62400C6B68E /* CGFloat.swift */, + DE1948C2277E958B0027AFC1 /* UIImage.swift */, ); path = Extensions; sourceTree = ""; @@ -808,6 +811,7 @@ DE7D991725D2B97A0053679C /* StudyCollectionViewCell.swift in Sources */, DE617B8125406210009FEE40 /* Card+CoreDataClass.swift in Sources */, DE4428D62547017100A8657C /* CollectionsView.swift in Sources */, + DE1948C3277E958B0027AFC1 /* UIImage.swift in Sources */, DE7D991E25D2C3840053679C /* FolderTableViewCell.swift in Sources */, DE77DAD724E6FE4D00095D73 /* AppDelegate.swift in Sources */, DEC5BA3F26224AF30082D846 /* UIButton.swift in Sources */, diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/foldert.imageset/Contents.json b/memo/Assets/Assets.xcassets/tabbar_icons/folder_selected.imageset/Contents.json similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/foldert.imageset/Contents.json rename to memo/Assets/Assets.xcassets/tabbar_icons/folder_selected.imageset/Contents.json diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/foldert.imageset/folder_tab.png b/memo/Assets/Assets.xcassets/tabbar_icons/folder_selected.imageset/folder_tab.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/foldert.imageset/folder_tab.png rename to memo/Assets/Assets.xcassets/tabbar_icons/folder_selected.imageset/folder_tab.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/foldert.imageset/folder_tab@2x.png b/memo/Assets/Assets.xcassets/tabbar_icons/folder_selected.imageset/folder_tab@2x.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/foldert.imageset/folder_tab@2x.png rename to memo/Assets/Assets.xcassets/tabbar_icons/folder_selected.imageset/folder_tab@2x.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/foldert.imageset/folder_tab@3x.png b/memo/Assets/Assets.xcassets/tabbar_icons/folder_selected.imageset/folder_tab@3x.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/foldert.imageset/folder_tab@3x.png rename to memo/Assets/Assets.xcassets/tabbar_icons/folder_selected.imageset/folder_tab@3x.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/foldert_unselected.imageset/Contents.json b/memo/Assets/Assets.xcassets/tabbar_icons/folder_unselected.imageset/Contents.json similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/foldert_unselected.imageset/Contents.json rename to memo/Assets/Assets.xcassets/tabbar_icons/folder_unselected.imageset/Contents.json diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/foldert_unselected.imageset/folder_unselected.png b/memo/Assets/Assets.xcassets/tabbar_icons/folder_unselected.imageset/folder_unselected.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/foldert_unselected.imageset/folder_unselected.png rename to memo/Assets/Assets.xcassets/tabbar_icons/folder_unselected.imageset/folder_unselected.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/foldert_unselected.imageset/folder_unselected@2x.png b/memo/Assets/Assets.xcassets/tabbar_icons/folder_unselected.imageset/folder_unselected@2x.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/foldert_unselected.imageset/folder_unselected@2x.png rename to memo/Assets/Assets.xcassets/tabbar_icons/folder_unselected.imageset/folder_unselected@2x.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/foldert_unselected.imageset/folder_unselected@3x.png b/memo/Assets/Assets.xcassets/tabbar_icons/folder_unselected.imageset/folder_unselected@3x.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/foldert_unselected.imageset/folder_unselected@3x.png rename to memo/Assets/Assets.xcassets/tabbar_icons/folder_unselected.imageset/folder_unselected@3x.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/search.imageset/Contents.json b/memo/Assets/Assets.xcassets/tabbar_icons/search_selected.imageset/Contents.json similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/search.imageset/Contents.json rename to memo/Assets/Assets.xcassets/tabbar_icons/search_selected.imageset/Contents.json diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/search.imageset/search.png b/memo/Assets/Assets.xcassets/tabbar_icons/search_selected.imageset/search.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/search.imageset/search.png rename to memo/Assets/Assets.xcassets/tabbar_icons/search_selected.imageset/search.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/search.imageset/search@2x.png b/memo/Assets/Assets.xcassets/tabbar_icons/search_selected.imageset/search@2x.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/search.imageset/search@2x.png rename to memo/Assets/Assets.xcassets/tabbar_icons/search_selected.imageset/search@2x.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/search.imageset/search@3x.png b/memo/Assets/Assets.xcassets/tabbar_icons/search_selected.imageset/search@3x.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/search.imageset/search@3x.png rename to memo/Assets/Assets.xcassets/tabbar_icons/search_selected.imageset/search@3x.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/settings.imageset/Contents.json b/memo/Assets/Assets.xcassets/tabbar_icons/settings_selected.imageset/Contents.json similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/settings.imageset/Contents.json rename to memo/Assets/Assets.xcassets/tabbar_icons/settings_selected.imageset/Contents.json diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/settings.imageset/settings.png b/memo/Assets/Assets.xcassets/tabbar_icons/settings_selected.imageset/settings.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/settings.imageset/settings.png rename to memo/Assets/Assets.xcassets/tabbar_icons/settings_selected.imageset/settings.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/settings.imageset/settings@2x.png b/memo/Assets/Assets.xcassets/tabbar_icons/settings_selected.imageset/settings@2x.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/settings.imageset/settings@2x.png rename to memo/Assets/Assets.xcassets/tabbar_icons/settings_selected.imageset/settings@2x.png diff --git a/memo/Assets/Assets.xcassets/tabbar_icons/settings.imageset/settings@3x.png b/memo/Assets/Assets.xcassets/tabbar_icons/settings_selected.imageset/settings@3x.png similarity index 100% rename from memo/Assets/Assets.xcassets/tabbar_icons/settings.imageset/settings@3x.png rename to memo/Assets/Assets.xcassets/tabbar_icons/settings_selected.imageset/settings@3x.png diff --git a/memo/Extensions/UIImage.swift b/memo/Extensions/UIImage.swift new file mode 100644 index 0000000..482e9a1 --- /dev/null +++ b/memo/Extensions/UIImage.swift @@ -0,0 +1,21 @@ +// +// UIImage.swift +// memo +// +// Created by Elias Ferreira on 30/12/21. +// Copyright © 2021 Academy IFCE. All rights reserved. +// + +import UIKit + +extension UIImage { + // TabBar Icons. + static let FOLDER_SELCTED = UIImage(named: "folder_selected") + static let FOLDER_UNSELECTED = UIImage(named: "folder_unselected") + static let SEARCH_SELECTED = UIImage(named: "search_selected") + static let SEARCH_UNSELECTED = UIImage(named: "search_unselected") + static let SETTINGS_SELECTED = UIImage(named: "settings_selected") + static let SETTINGS_UNSELECTED = UIImage(named: "settings_unselected") + + static let BACK_BUTTON = UIImage(named: "back_button") +} diff --git a/memo/UI/ViewControllers/SearchViewController.swift b/memo/UI/ViewControllers/SearchViewController.swift index 0585a6f..ba06c72 100644 --- a/memo/UI/ViewControllers/SearchViewController.swift +++ b/memo/UI/ViewControllers/SearchViewController.swift @@ -68,12 +68,12 @@ class SearchViewController: UIViewController { NSAttributedString.Key.font: UIFont.memoSemibold(ofSize: .mediumLarge), NSAttributedString.Key.foregroundColor: UIColor.memoText ] - let image = UIImage(named: "back_button") + let backButton = UIBarButtonItem() backButton.title = "" // Set the back button. - navigationController?.navigationBar.backIndicatorImage = image - navigationController?.navigationBar.backIndicatorTransitionMaskImage = image + navigationController?.navigationBar.backIndicatorImage = .BACK_BUTTON + navigationController?.navigationBar.backIndicatorTransitionMaskImage = .BACK_BUTTON navigationController?.navigationBar.topItem?.backBarButtonItem = backButton // Make the navigation bar background clear diff --git a/memo/UI/ViewControllers/TabBarController.swift b/memo/UI/ViewControllers/TabBarController.swift index 926b598..ac84fd1 100644 --- a/memo/UI/ViewControllers/TabBarController.swift +++ b/memo/UI/ViewControllers/TabBarController.swift @@ -30,16 +30,16 @@ class TabBarController: UITabBarController { // MARK: - Functions private func configItems() { // Collections - collectionsNavController?.tabBarItem.image = UIImage(named: "foldert_unselected") - collectionsNavController?.tabBarItem.selectedImage = UIImage(named: "foldert") + collectionsNavController?.tabBarItem.image = .FOLDER_UNSELECTED + collectionsNavController?.tabBarItem.selectedImage = .FOLDER_SELCTED collectionsNavController?.tabBarItem.imageInsets = UIEdgeInsets(top: 0, left: 0, bottom: -20, right: 0) // Search - searchNavController?.tabBarItem.image = UIImage(named: "search_unselected") - searchNavController?.tabBarItem.selectedImage = UIImage(named: "search") + searchNavController?.tabBarItem.image = .SEARCH_UNSELECTED + searchNavController?.tabBarItem.selectedImage = .SEARCH_SELECTED searchNavController?.tabBarItem.imageInsets = UIEdgeInsets(top: 0, left: 0, bottom: -20, right: 0) // Settings - settingsNavController?.tabBarItem.image = UIImage(named: "settings_unselected") - settingsNavController?.tabBarItem.selectedImage = UIImage(named: "settings") + settingsNavController?.tabBarItem.image = .SETTINGS_UNSELECTED + settingsNavController?.tabBarItem.selectedImage = .SEARCH_SELECTED settingsNavController?.tabBarItem.imageInsets = UIEdgeInsets(top: 0, left: 0, bottom: -20, right: 0) } From 53379293a86375f885abbf2e2ff853298d88be7e Mon Sep 17 00:00:00 2001 From: Elias Ferreira Date: Thu, 30 Dec 2021 22:48:47 -0300 Subject: [PATCH 3/3] wip --- memo/UI/ViewControllers/CollectionsViewController.swift | 5 ++--- memo/UI/ViewControllers/SettingsViewController.swift | 5 ++--- memo/UI/ViewControllers/TabBarController.swift | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/memo/UI/ViewControllers/CollectionsViewController.swift b/memo/UI/ViewControllers/CollectionsViewController.swift index bbd8ed9..e801777 100644 --- a/memo/UI/ViewControllers/CollectionsViewController.swift +++ b/memo/UI/ViewControllers/CollectionsViewController.swift @@ -87,12 +87,11 @@ class CollectionsViewController: UIViewController { NSAttributedString.Key.foregroundColor: UIColor.memoText ] - let image = UIImage(named: "back_button") let backButton = UIBarButtonItem() backButton.title = "" // Set the back button. - navigationController?.navigationBar.backIndicatorImage = image - navigationController?.navigationBar.backIndicatorTransitionMaskImage = image + navigationController?.navigationBar.backIndicatorImage = .BACK_BUTTON + navigationController?.navigationBar.backIndicatorTransitionMaskImage = .BACK_BUTTON navigationController?.navigationBar.topItem?.backBarButtonItem = backButton // Make the navigation bar background clear navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) diff --git a/memo/UI/ViewControllers/SettingsViewController.swift b/memo/UI/ViewControllers/SettingsViewController.swift index 02cc389..ef00059 100644 --- a/memo/UI/ViewControllers/SettingsViewController.swift +++ b/memo/UI/ViewControllers/SettingsViewController.swift @@ -47,12 +47,11 @@ class SettingsViewController: UIViewController { NSAttributedString.Key.foregroundColor: UIColor.memoText ] - let image = UIImage(named: "back_button") let backButton = UIBarButtonItem() backButton.title = "" // Set the back button. - navigationController?.navigationBar.backIndicatorImage = image - navigationController?.navigationBar.backIndicatorTransitionMaskImage = image + navigationController?.navigationBar.backIndicatorImage = .BACK_BUTTON + navigationController?.navigationBar.backIndicatorTransitionMaskImage = .BACK_BUTTON navigationController?.navigationBar.topItem?.backBarButtonItem = backButton // Make the navigation bar background clear navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) diff --git a/memo/UI/ViewControllers/TabBarController.swift b/memo/UI/ViewControllers/TabBarController.swift index ac84fd1..ed7e5e3 100644 --- a/memo/UI/ViewControllers/TabBarController.swift +++ b/memo/UI/ViewControllers/TabBarController.swift @@ -39,7 +39,7 @@ class TabBarController: UITabBarController { searchNavController?.tabBarItem.imageInsets = UIEdgeInsets(top: 0, left: 0, bottom: -20, right: 0) // Settings settingsNavController?.tabBarItem.image = .SETTINGS_UNSELECTED - settingsNavController?.tabBarItem.selectedImage = .SEARCH_SELECTED + settingsNavController?.tabBarItem.selectedImage = .SETTINGS_SELECTED settingsNavController?.tabBarItem.imageInsets = UIEdgeInsets(top: 0, left: 0, bottom: -20, right: 0) }