Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Commit

Permalink
Better way of fetching json
Browse files Browse the repository at this point in the history
Made by me
  • Loading branch information
AppInstalleriOSGH authored Nov 12, 2022
1 parent 732daf6 commit 619d47d
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions TrollApps/TrollApps/JSONStuff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,17 @@ struct stuff: Codable, Identifiable {
var id: Int
var title: String
var link: String
var prevlink: String
//No items in the json has this yet
//var prevlink: String
var urlimg: String
var completed: Bool
}

class fetchtd: ObservableObject {
@Published var jsonstuff = [stuff]()

init() {
let url = URL(string: "https://haxi0-dev.com/api/trollapps-0.1.json")!
URLSession.shared.dataTask(with: url) {(data, response, error) in
do {
if let jsondata = data {
let decodeddata = try JSONDecoder().decode([stuff].self, from: jsondata)
DispatchQueue.main.async {
self.jsonstuff = decodeddata
}
} else {
print("no data")
}
} catch {
print("oopsie")
}
}.resume()
func FetchApps() -> [stuff] {
do {
return try JSONDecoder().decode([stuff].self, from: try! Data(contentsOf: URL(string: "https://haxi0-dev.com/api/trollapps-0.1.json")!))
} catch {
print("oopsie")
return []
}
}

0 comments on commit 619d47d

Please sign in to comment.