-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewController.swift
95 lines (68 loc) · 2.8 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// ViewController.swift
// RESThub
//
// Created by Harrison on 7/25/19.
// Copyright © 2019 Harrison. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
// MARK: Outlets
@IBOutlet weak var feedTableView: UITableView!
// MARK: Variables
override func viewDidLoad() {
super.viewDidLoad()
let testGist = Gist(id: nil, isPublic: true, description: "Hello World!")
do {
let gistData = try JSONEncoder().encode(testGist)
let stringData = String(data: gistData, encoding: .utf8)
print(stringData)
} catch {
print("Encoding failed...")
}
// TODO: GET a list of gists
DataService.shared.fetchGists { (result) in
switch result {
case .success(let gists):
for gist in gists {
print("\(gist)\n")
}
case .failure(let error):
print(error)
}
}
}
@IBAction func createNewGist(_ sender: UIButton) {
// TODO: POST a new gist
}
// MARK: Utilities
func showResultAlert(title: String, message: String) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: .default))
self.present(alertController, animated: true, completion: nil)
}
}
// MARK: UITableView Delegate & DataSource
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1;
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "feedCellID", for: indexPath)
return cell;
}
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let starAction = UIContextualAction(style: .normal, title: "Star") { (action, view, completion) in
// TODO: PUT a gist star
completion(true)
}
let unstarAction = UIContextualAction(style: .normal, title: "Unstar") { (action, view, completion) in
// TODO: DELETE a gist star
completion(true)
}
starAction.backgroundColor = .blue
unstarAction.backgroundColor = .darkGray
let actionConfig = UISwipeActionsConfiguration(actions: [unstarAction, starAction])
return actionConfig
}
}