-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoteView.swift
58 lines (41 loc) · 1.14 KB
/
NoteView.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
//
// NoteView.swift
// Note-App
//
// Created by Ayush S on 2024-07-12.
//
import SwiftUI
protocol DataDelegate {
func updateArray(newArray: String)
}
struct NoteView: View {
@State var notes = [Note]()
var body: some View {
NavigationStack {
List{
ForEach(notes, id: \.self) { note in
NavigationLink(note.title) {
Text("Go to screen 1")
}.navigationTitle("Notes.")
}
}.onAppear(){
APIFunctions.functions.delegate = self
APIFunctions.functions.fetchNotes()
}
}
}
}
extension NoteView: DataDelegate {
func updateArray(newArray: String) {
do {
let decoder = JSONDecoder()
notes = try decoder.decode([Note].self, from: newArray.data(using: .utf8)!)
print (notes)
} catch {
print("failed to decode!")
}
}
}
#Preview {
NoteView()
}