Skip to content
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
26 changes: 26 additions & 0 deletions ListApp/Controllers/ItemsController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// ItemsController.swift
// ListApp
//
// Created by Nelson Gonzalez on 1/8/19.
// Copyright © 2019 Nelson Gonzalez. All rights reserved.
//

import Foundation

class ItemsController {
var items = [String]()
let bullets = "\u{2022}"

func add(_ item: String) {
// add the item to your items list
items.append(bullets + " " + item)

}

func resetItems() {
items.removeAll()
}


}
60 changes: 60 additions & 0 deletions ListApp/Controllers/ViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// ViewController.swift
// ListApp
//
// Created by Nelson Gonzalez on 1/8/19.
// Copyright © 2019 Nelson Gonzalez. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var textField: UITextField!

@IBOutlet weak var label: UILabel!



var itemsController = ItemsController()


override func viewDidLoad() {
super.viewDidLoad()

updateViews()

}

func updateViews(){
label.text = nil
}


@IBAction func shouldAdd(_ sender: UIButton) {

let text = textField.text ?? ""

if !text.isEmpty {
itemsController.add(text)
textField.text = ""
} else {
print("No")
}
let joined = itemsController.items.joined(separator: "\n")
label.text = joined

}

@IBAction func shouldReset(_ sender: UIButton) {
itemsController.resetItems()
updateViews()
}

@IBAction func printButton(_ sender: UIButton) {

print(itemsController.items)
}

}

Loading