Lessons implementation
This commit is contained in:
@@ -31,6 +31,17 @@ class TokiJSONLoader: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
func loadLessons() -> [TokiLesson]? {
|
||||
let jsonData = loadJSON("toki-lessons")
|
||||
do {
|
||||
let decodedData = try JSONDecoder().decode([TokiLesson].self, from: jsonData!)
|
||||
return decodedData
|
||||
} catch {
|
||||
print("Decode error: \(error)")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func loadJSON(_ resource: String) -> Data? {
|
||||
do {
|
||||
if let bundlePath = Bundle.main.path(forResource: resource, ofType: "json"), let jsonData = try String(contentsOfFile: bundlePath).data(using: .utf8) {
|
||||
|
15
Toki Trainer/Models/TokiLesson.swift
Normal file
15
Toki Trainer/Models/TokiLesson.swift
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// TokiLesson.swift
|
||||
// Toki Trainer
|
||||
//
|
||||
// Created by Avery Ada Pace on 11/8/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct TokiLesson: Decodable {
|
||||
var lesson: String
|
||||
var words: [TokiDictEntry]
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user