Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // MyJson.swift
- // Quotter
- //
- // Created by Alex Belov on 11/11/2018.
- // Copyright © 2018 Alex Belov. All rights reserved.
- //
- import Foundation
- struct quotesDB: Codable {
- let listofQuotes: [String]
- let theme: String
- }
- class JsonHelper {
- private let file = "quotes.json"
- private let filePath = Bundle.main.path(forResource: "quotes", ofType: "json")
- private var jsonString = ""
- func getDataBase() -> [quotesDB]{
- do{
- jsonString = try String(contentsOf: URL(fileURLWithPath: filePath!))
- } catch{
- print("Error reading json")
- }
- let data = jsonString.data(using: .utf8)!
- let decoder = JSONDecoder()
- return try! decoder.decode([quotesDB].self, from: data) // There's array of quotesDb structs
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement