Permalink
Browse files

Convert to MVC design pattern A lot of shit I don't understands

  • Loading branch information...
Seth Chavis Seth Chavis
Seth Chavis authored and Seth Chavis committed Jan 13, 2018
1 parent d836a4e commit cecee4c62f624db3cd7ae46aaa24b56ab14d9946
@@ -12,6 +12,7 @@
91601F75200817020082F7B1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 91601F73200817020082F7B1 /* Main.storyboard */; };
91601F77200817020082F7B1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 91601F76200817020082F7B1 /* Assets.xcassets */; };
91601F7A200817020082F7B1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 91601F78200817020082F7B1 /* LaunchScreen.storyboard */; };
91601F822009A7130082F7B1 /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91601F812009A7130082F7B1 /* Item.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -22,6 +23,7 @@
91601F76200817020082F7B1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
91601F79200817020082F7B1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
91601F7B200817020082F7B1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
91601F812009A7130082F7B1 /* Item.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Item.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -55,13 +57,46 @@
isa = PBXGroup;
children = (
91601F6F200817020082F7B1 /* AppDelegate.swift */,
91601F842009A7320082F7B1 /* Controllers */,
91601F832009A7180082F7B1 /* Data Model */,
91601F852009A73D0082F7B1 /* Views */,
91601F862009A7530082F7B1 /* Supporting Files */,
91601F7B200817020082F7B1 /* Info.plist */,
);
path = Listie;
sourceTree = "<group>";
};
91601F832009A7180082F7B1 /* Data Model */ = {
isa = PBXGroup;
children = (
91601F812009A7130082F7B1 /* Item.swift */,
);
path = "Data Model";
sourceTree = "<group>";
};
91601F842009A7320082F7B1 /* Controllers */ = {
isa = PBXGroup;
children = (
91601F71200817020082F7B1 /* TodoListViewController.swift */,
);
path = Controllers;
sourceTree = "<group>";
};
91601F852009A73D0082F7B1 /* Views */ = {
isa = PBXGroup;
children = (
91601F73200817020082F7B1 /* Main.storyboard */,
);
path = Views;
sourceTree = "<group>";
};
91601F862009A7530082F7B1 /* Supporting Files */ = {
isa = PBXGroup;
children = (
91601F76200817020082F7B1 /* Assets.xcassets */,
91601F78200817020082F7B1 /* LaunchScreen.storyboard */,
91601F7B200817020082F7B1 /* Info.plist */,
);
path = Listie;
path = "Supporting Files";
sourceTree = "<group>";
};
/* End PBXGroup section */
@@ -137,6 +172,7 @@
buildActionMask = 2147483647;
files = (
91601F72200817020082F7B1 /* TodoListViewController.swift in Sources */,
91601F822009A7130082F7B1 /* Item.swift in Sources */,
91601F70200817020082F7B1 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
View
@@ -16,7 +16,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
print(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last! as String)
return true
}
@@ -11,35 +11,53 @@ import UIKit
class TodoListViewController: UITableViewController{
var itemArray = ["Buy Eggs", "Buy Waffles", "Buy Milk"]
var itemArray = [Item]()
let defaults = UserDefaults.standard
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if let items = defaults.array(forKey: "ToDoListArray") as? [String] {
let newItem = Item()
newItem.title = "Buy Eggs"
itemArray.append(newItem)
let newItem2 = Item()
newItem2.title = "Buy Waffles"
itemArray.append(newItem2)
let newItem3 = Item()
newItem3.title = "Buy Grits"
itemArray.append(newItem3)
if let items = defaults.array(forKey: "ToDoListArray") as? [Item] {
itemArray = items
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ToDoItemCell", for: indexPath)
cell.textLabel?.text = itemArray[indexPath.row]
let cell = UITableViewCell(style: .default, reuseIdentifier: "ToDoItemCell")
let item = itemArray[indexPath.row]
cell.textLabel?.text = item.title
//Ternary Operator
// Value = condition ? ValueIfTrue : valueIfFalse
cell.accessoryType = item.done ? .checkmark : . none
return cell
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemArray.count
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(itemArray[indexPath.row])
//print(itemArray[indexPath.row])
itemArray[indexPath.row].done = !itemArray[indexPath.row].done
if tableView.cellForRow(at: indexPath)?.accessoryType == .checkmark {
tableView.cellForRow(at: indexPath)?.accessoryType = .none
} else {
tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
}
tableView.reloadData()
tableView.deselectRow(at: indexPath, animated: true)
}
//Mark - Add new items
@@ -49,7 +67,11 @@ class TodoListViewController: UITableViewController{
let alert = UIAlertController(title: "Add new Listie item", message: "", preferredStyle: .alert)
let action = UIAlertAction(title: "Add item", style: .default) { (action) in
//What will happen when user click add item button
self.itemArray.append(textField.text!)
let newItem = Item()
newItem.title = textField.text!
self.itemArray.append(newItem)
self.defaults.set(self.itemArray, forKey: "ToDoListArray")
self.tableView.reloadData()
@@ -0,0 +1,15 @@
//
// Item.swift
// Listie
//
// Created by Seth Chavis on 1/12/18.
// Copyright © 2018 Joseth Chavis. All rights reserved.
//
import Foundation
class Item {
var title : String = ""
var done : Bool = false
}
@@ -84,6 +84,11 @@
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {

0 comments on commit cecee4c

Please sign in to comment.