Commit 11eb6062 authored by tybrandt's avatar tybrandt
Browse files

Category table reformatted, all data in main view updates, all transactions view started

parent af14f4aa
......@@ -7,6 +7,9 @@
objects = {
/* Begin PBXBuildFile section */
DE053E98260477660015C753 /* TransactionTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE053E97260477660015C753 /* TransactionTableViewController.swift */; };
DE053EA02604789B0015C753 /* TransactionTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE053E9F2604789B0015C753 /* TransactionTableViewCell.swift */; };
DE053EA5260478B70015C753 /* Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE053EA4260478B70015C753 /* Transaction.swift */; };
DE512D0225FB039A00EA7816 /* Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE512D0125FB039A00EA7816 /* Category.swift */; };
DEC2565A25E887410003EFC9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2565925E887410003EFC9 /* AppDelegate.swift */; };
DEC2565C25E887410003EFC9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2565B25E887410003EFC9 /* SceneDelegate.swift */; };
......@@ -38,6 +41,9 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
DE053E97260477660015C753 /* TransactionTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionTableViewController.swift; sourceTree = "<group>"; };
DE053E9F2604789B0015C753 /* TransactionTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionTableViewCell.swift; sourceTree = "<group>"; };
DE053EA4260478B70015C753 /* Transaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Transaction.swift; sourceTree = "<group>"; };
DE512D0125FB039A00EA7816 /* Category.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Category.swift; sourceTree = "<group>"; };
DEC2565625E887410003EFC9 /* Budget Tracker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Budget Tracker.app"; sourceTree = BUILT_PRODUCTS_DIR; };
DEC2565925E887410003EFC9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
......@@ -110,6 +116,9 @@
DEC2565D25E887410003EFC9 /* CategoryViewController.swift */,
DEEC3BC625FB1EFA00011733 /* CategoryTableViewCell.swift */,
DE512D0125FB039A00EA7816 /* Category.swift */,
DE053E97260477660015C753 /* TransactionTableViewController.swift */,
DE053E9F2604789B0015C753 /* TransactionTableViewCell.swift */,
DE053EA4260478B70015C753 /* Transaction.swift */,
DEC2569A25E89A400003EFC9 /* AddTransactionViewController.swift */,
DEC2565F25E887410003EFC9 /* Main.storyboard */,
DEC2566225E887440003EFC9 /* Assets.xcassets */,
......@@ -269,10 +278,13 @@
files = (
DEC2565E25E887410003EFC9 /* CategoryViewController.swift in Sources */,
DE512D0225FB039A00EA7816 /* Category.swift in Sources */,
DE053EA02604789B0015C753 /* TransactionTableViewCell.swift in Sources */,
DE053E98260477660015C753 /* TransactionTableViewController.swift in Sources */,
DEC2565A25E887410003EFC9 /* AppDelegate.swift in Sources */,
DEC2565C25E887410003EFC9 /* SceneDelegate.swift in Sources */,
DEC2569B25E89A400003EFC9 /* AddTransactionViewController.swift in Sources */,
DEEC3BC725FB1EFA00011733 /* CategoryTableViewCell.swift in Sources */,
DE053EA5260478B70015C753 /* Transaction.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -37,6 +37,9 @@
<state key="normal" title="TRANSACTIONS">
<color key="titleColor" systemColor="systemIndigoColor"/>
</state>
<connections>
<segue destination="fMk-k4-n9V" kind="show" id="vPX-cl-Jc3"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Total: $0.00" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bay-ph-RNu">
<rect key="frame" x="20" y="787" width="374" height="29"/>
......@@ -48,34 +51,37 @@
<rect key="frame" x="20" y="88" width="374" height="691"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="CategoryTableViewCell" id="way-ii-Wwy" customClass="CategoryTableViewCell" customModule="Budget_Tracker" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="374" height="21.5"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="CategoryTableViewCell" rowHeight="40" id="way-ii-Wwy" customClass="CategoryTableViewCell" customModule="Budget_Tracker" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="374" height="40"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="way-ii-Wwy" id="9Fx-Di-qVx">
<rect key="frame" x="0.0" y="0.0" width="374" height="21.5"/>
<rect key="frame" x="0.0" y="0.0" width="374" height="40"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Price" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6fu-Bu-LnA">
<rect key="frame" x="312.5" y="0.0" width="41.5" height="22"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Name" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6pf-vN-yV5">
<rect key="frame" x="20" y="6" width="61.5" height="29"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6pf-vN-yV5">
<rect key="frame" x="20" y="0.0" width="285" height="21.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Price" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6fu-Bu-LnA">
<rect key="frame" x="253.5" y="6" width="100" height="29"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="100" id="cmS-Vs-uZA"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="6fu-Bu-LnA" secondAttribute="trailing" constant="20" symbolic="YES" id="Ctv-sD-hNg"/>
<constraint firstItem="6fu-Bu-LnA" firstAttribute="leading" secondItem="6pf-vN-yV5" secondAttribute="trailing" constant="7.5" id="KOi-jR-qXp"/>
<constraint firstAttribute="bottom" secondItem="6pf-vN-yV5" secondAttribute="bottom" id="Tca-4b-CwV"/>
<constraint firstItem="6pf-vN-yV5" firstAttribute="top" secondItem="9Fx-Di-qVx" secondAttribute="top" id="V5H-KO-LRS"/>
<constraint firstAttribute="bottom" secondItem="6fu-Bu-LnA" secondAttribute="bottom" constant="-0.5" id="W6a-nc-6mI"/>
<constraint firstItem="6pf-vN-yV5" firstAttribute="leading" secondItem="9Fx-Di-qVx" secondAttribute="leading" constant="20" symbolic="YES" id="gDc-kW-U0f"/>
<constraint firstItem="6fu-Bu-LnA" firstAttribute="top" secondItem="9Fx-Di-qVx" secondAttribute="top" id="xOz-1s-Yv0"/>
<constraint firstItem="6pf-vN-yV5" firstAttribute="top" secondItem="9Fx-Di-qVx" secondAttribute="top" constant="6" id="AnG-wd-lrG"/>
<constraint firstAttribute="bottom" secondItem="6fu-Bu-LnA" secondAttribute="bottom" constant="5" id="HW9-up-tGu"/>
<constraint firstAttribute="bottom" secondItem="6pf-vN-yV5" secondAttribute="bottom" constant="5" id="Mbe-dC-qPA"/>
<constraint firstItem="6pf-vN-yV5" firstAttribute="leading" secondItem="9Fx-Di-qVx" secondAttribute="leading" constant="20" symbolic="YES" id="Sx7-15-ZpY"/>
<constraint firstAttribute="trailing" secondItem="6fu-Bu-LnA" secondAttribute="trailing" constant="20.5" id="VSr-j4-aTP"/>
<constraint firstItem="6fu-Bu-LnA" firstAttribute="top" secondItem="9Fx-Di-qVx" secondAttribute="top" constant="6" id="WjY-qE-2LK"/>
<constraint firstItem="6fu-Bu-LnA" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="6pf-vN-yV5" secondAttribute="trailing" constant="8" symbolic="YES" id="hvO-lV-Kko"/>
</constraints>
</tableViewCellContentView>
<connections>
......@@ -118,6 +124,7 @@
<navigationItem key="navigationItem" title="Budget Tracker" id="p8f-H0-k1k"/>
<connections>
<outlet property="categoryTable" destination="2vd-QX-gXm" id="RVa-T8-OWz"/>
<outlet property="totalLabel" destination="bay-ph-RNu" id="2af-D9-cpa"/>
<segue destination="JIR-F4-P6s" kind="presentation" identifier="addTransaction" id="4xG-2T-kn9"/>
</connections>
</viewController>
......@@ -125,6 +132,58 @@
</objects>
<point key="canvasLocation" x="950.72463768115949" y="164.73214285714286"/>
</scene>
<!--All Transactions-->
<scene sceneID="9Bx-fx-jyj">
<objects>
<tableViewController id="G1A-Zz-7cZ" customClass="TransactionTableViewController" customModule="Budget_Tracker" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="qlF-bW-DX7">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="allTransactions" id="e68-D8-BFK" customClass="TransactionTableViewCell" customModule="Budget_Tracker" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="e68-D8-BFK" id="Q12-f8-IYE">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ZQh-dN-pAc">
<rect key="frame" x="20" y="11" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="ZQh-dN-pAc" firstAttribute="top" secondItem="Q12-f8-IYE" secondAttribute="topMargin" id="3HX-yH-7bM"/>
<constraint firstItem="ZQh-dN-pAc" firstAttribute="leading" secondItem="Q12-f8-IYE" secondAttribute="leadingMargin" id="Ze3-CE-NrL"/>
<constraint firstAttribute="bottomMargin" secondItem="ZQh-dN-pAc" secondAttribute="bottom" constant="0.5" id="pvp-fP-BeH"/>
<constraint firstAttribute="trailingMargin" relation="lessThanOrEqual" secondItem="ZQh-dN-pAc" secondAttribute="trailing" constant="332" id="yMY-ib-KtU"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="name" destination="ZQh-dN-pAc" id="BAX-R7-zkd"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="G1A-Zz-7cZ" id="tgD-IM-ZeE"/>
<outlet property="delegate" destination="G1A-Zz-7cZ" id="v5d-PW-7nE"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="All Transactions" id="xym-6q-kXb">
<barButtonItem key="leftBarButtonItem" systemItem="done" id="8Tp-4a-EE7">
<connections>
<action selector="goBack:" destination="G1A-Zz-7cZ" id="sRB-vx-BSN"/>
</connections>
</barButtonItem>
</navigationItem>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Vnp-er-RtW" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2812" y="530"/>
</scene>
<!--Add Transaction-->
<scene sceneID="jMr-WU-dY7">
<objects>
......@@ -186,7 +245,7 @@
<placeholder placeholderIdentifier="IBFirstResponder" id="jOc-cA-MFX" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
<exit id="ZYl-Ei-Xw9" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="2862.3188405797105" y="164.73214285714286"/>
<point key="canvasLocation" x="2812" y="-194"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="h9C-C0-k84">
......@@ -209,7 +268,6 @@
<!--Navigation Controller-->
<scene sceneID="qn1-CW-M5d">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="HJa-Mg-ThC" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="JIR-F4-P6s" sceneMemberID="viewController">
<toolbarItems/>
<navigationItem key="navigationItem" id="bC3-KK-vVK"/>
......@@ -222,8 +280,28 @@
<segue destination="UPP-cu-IDS" kind="relationship" relationship="rootViewController" id="oft-4s-nUu"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="HJa-Mg-ThC" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1848" y="-194"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="FS8-hY-hF7">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="fMk-k4-n9V" sceneMemberID="viewController">
<toolbarItems/>
<navigationItem key="navigationItem" id="JYS-JJ-2My"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="VIw-U5-2AY">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="G1A-Zz-7cZ" kind="relationship" relationship="rootViewController" id="SIE-hr-SbD"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="pSl-yP-Ti1" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1899" y="753"/>
<point key="canvasLocation" x="1848" y="530"/>
</scene>
</scenes>
<resources>
......
......@@ -10,12 +10,17 @@ import UIKit
class CategoryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var categories = [Category]()
@IBOutlet weak var categoryTable: UITableView!
@IBOutlet weak var totalLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
if let savedCategories = loadCategories() {
print("SUCCESS")
categories += savedCategories
var total = 0.0
for category in categories {
total += category.price
}
totalLabel.text = String(format: "Total: $%.2f", total)
}
categoryTable.delegate = self
categoryTable.dataSource = self
......@@ -30,7 +35,11 @@ class CategoryViewController: UIViewController, UITableViewDelegate, UITableView
categories = sourceView.categories
saveCategories()
categoryTable.reloadData()
print(categories)
var total = 0.0
for category in categories {
total += category.price
}
totalLabel.text = String(format: "Total: $%.2f", total)
}
}
......@@ -62,7 +71,7 @@ class CategoryViewController: UIViewController, UITableViewDelegate, UITableView
}
let category = categories[indexPath.row]
cell.name.text = category.name
cell.price.text = String(category.price)
cell.price.text = String(format: "$%.2f", category.price)
return cell
}
......
//
// Transaction.swift
// Budget Tracker
//
// Created by Tyler Brandt on 3/19/21.
//
import UIKit
class Transaction: NSObject, NSCoding {
var name: String
var category: String
var price: Double
static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
static let ArchiveURL = DocumentsDirectory.appendingPathComponent("transactions")
struct PropertyKey {
static let name = "name"
}
init?(name: String) {
self.name = name
self.category = ""
self.price = 0.0
}
func encode(with coder: NSCoder) {
coder.encode(name, forKey: PropertyKey.name)
}
required convenience init?(coder: NSCoder) {
guard let name = coder.decodeObject(forKey: PropertyKey.name) as? String else {return nil}
self.init(name: name)
}
}
//
// TransactionTableViewCell.swift
// Budget Tracker
//
// Created by Tyler Brandt on 3/19/21.
//
import UIKit
class TransactionTableViewCell: UITableViewCell {
@IBOutlet weak var name: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
//
// TransactionTableViewController.swift
// Budget Tracker
//
// Created by Tyler Brandt on 3/19/21.
//
import UIKit
class TransactionTableViewController: UITableViewController {
var transactions = [Transaction]()
override func viewDidLoad() {
super.viewDidLoad()
let transaction = Transaction(name: "No Transactions")
transactions.append(transaction!)
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return transactions.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "allTransactions"
guard let cell = self.tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as?
TransactionTableViewCell else {
fatalError()
}
let transaction = transactions[indexPath.row]
cell.name.text = transaction.name
return cell
}
@IBAction func goBack(_ sender: UIBarButtonItem) {
dismiss(animated: true, completion: nil)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment