mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-03-28 20:22:02 +01:00
Add projects
This commit is contained in:
38
Examples/UINote/SwiftUINote/Models/NoteData.swift
Executable file
38
Examples/UINote/SwiftUINote/Models/NoteData.swift
Executable file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// NoteData.swift
|
||||
// SwiftUINote
|
||||
//
|
||||
// Created by chanju Jeon on 05/06/2019.
|
||||
// Copyright © 2019 we'd. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
class NoteData {
|
||||
|
||||
static let shared = NoteData()
|
||||
|
||||
var notes: [Note] = [
|
||||
Note(text: "New Note"),
|
||||
Note(text: "Another Note")
|
||||
]
|
||||
|
||||
private init() { load() }
|
||||
|
||||
static func dateToString(date: Date) -> String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
return formatter.string(from: date)
|
||||
}
|
||||
|
||||
func save() {
|
||||
UserDefaults.standard.set(try? PropertyListEncoder().encode(notes), forKey: "notes")
|
||||
debugPrint("save called")
|
||||
}
|
||||
|
||||
func load() {
|
||||
if let data = UserDefaults.standard.object(forKey: "notes") as? Data {
|
||||
self.notes = try! PropertyListDecoder().decode([Note].self, from: data)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user