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
20 changes: 20 additions & 0 deletions Tasks.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
8BD0818F26F894270008ED22 /* Task.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BD0818E26F894270008ED22 /* Task.swift */; };
8BD0819326F89DED0008ED22 /* TaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BD0819226F89DED0008ED22 /* TaskViewController.swift */; };
8BD0819526F8A9A80008ED22 /* Tasks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BD0819426F8A9A80008ED22 /* Tasks.swift */; };
8BF3739F26F1F00C0017A890 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BF3739E26F1F00C0017A890 /* AppDelegate.swift */; };
8BF373A126F1F00C0017A890 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BF373A026F1F00C0017A890 /* SceneDelegate.swift */; };
8BF373A326F1F00C0017A890 /* AllTasksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BF373A226F1F00C0017A890 /* AllTasksViewController.swift */; };
Expand All @@ -17,6 +20,9 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
8BD0818E26F894270008ED22 /* Task.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Task.swift; sourceTree = "<group>"; };
8BD0819226F89DED0008ED22 /* TaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskViewController.swift; sourceTree = "<group>"; };
8BD0819426F8A9A80008ED22 /* Tasks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tasks.swift; sourceTree = "<group>"; };
8BF3739B26F1F00C0017A890 /* Tasks.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tasks.app; sourceTree = BUILT_PRODUCTS_DIR; };
8BF3739E26F1F00C0017A890 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
8BF373A026F1F00C0017A890 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -39,6 +45,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
8BD0819626F8E0150008ED22 /* Models */ = {
isa = PBXGroup;
children = (
8BD0818E26F894270008ED22 /* Task.swift */,
8BD0819426F8A9A80008ED22 /* Tasks.swift */,
);
path = Models;
sourceTree = "<group>";
};
8BF3739226F1F00C0017A890 = {
isa = PBXGroup;
children = (
Expand All @@ -58,6 +73,7 @@
8BF3739D26F1F00C0017A890 /* Tasks */ = {
isa = PBXGroup;
children = (
8BD0819626F8E0150008ED22 /* Models */,
8BF373B326F1F5150017A890 /* Controllers */,
8BF373B226F1F1D40017A890 /* Resources */,
8BF3739E26F1F00C0017A890 /* AppDelegate.swift */,
Expand All @@ -82,6 +98,7 @@
children = (
8BF373A226F1F00C0017A890 /* AllTasksViewController.swift */,
8BF373B426F1F5300017A890 /* AddTaskViewController.swift */,
8BD0819226F89DED0008ED22 /* TaskViewController.swift */,
);
path = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -157,7 +174,10 @@
buildActionMask = 2147483647;
files = (
8BF373A326F1F00C0017A890 /* AllTasksViewController.swift in Sources */,
8BD0819326F89DED0008ED22 /* TaskViewController.swift in Sources */,
8BF373B526F1F5300017A890 /* AddTaskViewController.swift in Sources */,
8BD0818F26F894270008ED22 /* Task.swift in Sources */,
8BD0819526F8A9A80008ED22 /* Tasks.swift in Sources */,
8BF3739F26F1F00C0017A890 /* AppDelegate.swift in Sources */,
8BF373A126F1F00C0017A890 /* SceneDelegate.swift in Sources */,
);
Expand Down
14 changes: 14 additions & 0 deletions Tasks/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let task1 = Task(description: "Task 1", main: true)
let task2 = Task(description: "Task 2", main: true)
let task3 = Task(description: "Task 3", main: true)
let task4 = Task(description: "Task 4", main: true)
let task5 = Task(description: "Task 5", main: true)
let task6 = Task(description: "Task 6", main: true)
let task7 = Task(description: "Task 7", main: false)
let task8 = Task(description: "Task 8", main: false)
let task9 = Task(description: "Task 9", main: false)
let task10 = Task(description: "Task 10", main: false)
task1.tasks = [task8, task9, task10]
task10.tasks = [task7]

Tasks.shared.tasks = [task1, task2, task3, task4, task5, task6, task7, task8, task9, task10]
return true
}

Expand Down
16 changes: 16 additions & 0 deletions Tasks/Controllers/AddTaskViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,23 @@ import UIKit

class AddTaskViewController: UIViewController {

@IBOutlet weak var taskTextView: UITextView!

var parentTask: Task?

override func viewDidLoad() {
super.viewDidLoad()
}

@IBAction func saveTaskTapped(_ sender: Any) {
guard let description = taskTextView.text else { return }
let main = parentTask == nil

let newTask = Task(description: description, main: main)

Tasks.shared.tasks.append(newTask)
parentTask?.tasks.append(newTask)

navigationController?.popViewController(animated: true)
}
}
53 changes: 53 additions & 0 deletions Tasks/Controllers/AllTasksViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,61 @@ import UIKit

class AllTasksViewController: UIViewController {

@IBOutlet weak var tasksTableView: UITableView!

var tasks: [Task] = []

override func viewDidLoad() {
super.viewDidLoad()

tasksTableView.delegate = self
tasksTableView.dataSource = self
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

// TODO: Сделать хранение задач в Realm (например)
self.tasks = []

for task in Tasks.shared.tasks {
if task.main {
self.tasks.append(task)
}
}

tasksTableView.reloadData()
}
}

extension AllTasksViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tasks.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return tableView.dequeueReusableCell(withIdentifier: "TaskCellIdentifier", for: indexPath)
}

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let task = tasks[indexPath.row]
cell.textLabel?.text = task.description
cell.detailTextLabel?.text = String(task.tasks.count)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showTaskSegue" {
guard let taskViewController = segue.destination as? TaskViewController else { return }

guard let indexPath = sender as? IndexPath else { return }
let task = tasks[indexPath.row]

taskViewController.currentTask = task
}
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "showTaskSegue", sender: indexPath)
}
}

60 changes: 60 additions & 0 deletions Tasks/Controllers/TaskViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// TaskViewController.swift
// Tasks
//
// Created by Кирилл Копытин on 20.09.2021.
//

import UIKit

class TaskViewController: UIViewController {

var currentTask: Task!

@IBOutlet weak var descriptionTaskLabel: UILabel!
@IBOutlet weak var tasksTableView: UITableView!

override func viewDidLoad() {
super.viewDidLoad()

descriptionTaskLabel.text = currentTask.description

tasksTableView.delegate = self
tasksTableView.dataSource = self
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

tasksTableView.reloadData()
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showAddTaskSegue" {
guard let addTaskViewController = segue.destination as? AddTaskViewController else { return }
addTaskViewController.parentTask = currentTask
}
}
}

extension TaskViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return currentTask.tasks.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return tableView.dequeueReusableCell(withIdentifier: "TaskCellIdentifier", for: indexPath)
}

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let task = currentTask.tasks[indexPath.row]
cell.textLabel?.text = task.description
cell.detailTextLabel?.text = String(task.tasks.count)
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.currentTask = currentTask.tasks[indexPath.row]
descriptionTaskLabel.text = currentTask.description
tableView.reloadData()
}
}
20 changes: 20 additions & 0 deletions Tasks/Models/Task.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Task.swift
// Tasks
//
// Created by Кирилл Копытин on 20.09.2021.
//

import Foundation

class Task {
let description: String
let main: Bool

var tasks: [Task] = []

init(description: String, main: Bool) {
self.description = description
self.main = main
}
}
16 changes: 16 additions & 0 deletions Tasks/Models/Tasks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Tasks.swift
// Tasks
//
// Created by Кирилл Копытин on 20.09.2021.
//

import Foundation

final class Tasks {
static let shared = Tasks()

private init() {}

var tasks: [Task] = []
}
Loading