Lessons implementation

This commit is contained in:
Avery Pace
2021-11-08 12:24:46 -05:00
parent c2d0dfa5e6
commit 3bce439bc4
7 changed files with 142 additions and 30 deletions

View File

@@ -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) {

View 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]
}