Skip to content

Remove force unwrap on TabBarController #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion memo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
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 = "<group>"; };
DE4428D02546FBC200A8657C /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = "<group>"; };
DE4428D52547017100A8657C /* CollectionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionsView.swift; sourceTree = "<group>"; };
DE4428F12547238200A8657C /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -477,6 +479,7 @@
DE8E82CA2548A9050067899B /* UITextField.swift */,
DEEC9DE226000E67005259C0 /* UIImageView.swift */,
DE8779532630A62400C6B68E /* CGFloat.swift */,
DE1948C2277E958B0027AFC1 /* UIImage.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
21 changes: 21 additions & 0 deletions memo/Extensions/UIImage.swift
Original file line number Diff line number Diff line change
@@ -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")
}
5 changes: 2 additions & 3 deletions memo/UI/ViewControllers/CollectionsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions memo/UI/ViewControllers/SearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions memo/UI/ViewControllers/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 17 additions & 11 deletions memo/UI/ViewControllers/TabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,31 @@ 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 = .SETTINGS_SELECTED
settingsNavController?.tabBarItem.imageInsets = UIEdgeInsets(top: 0, left: 0, bottom: -20, right: 0)
}

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() {
Expand Down