My app runs flawlessly when simulated and when it is run on my iPhone. But in the preview it crashes.
I have included the crash logs.
Thank you, Jude
My app runs flawlessly when simulated and when it is run on my iPhone. But in the preview it crashes.
I have included the crash logs.
Thank you, Jude
Hi,
Sorry to hear you are having problems getting previews working. It looks like the crash is occurring in your code at ExploreDataService.swift:31. If you inspect that area do you see what could be crashing? Otherwise maybe you can post that code and we can take a look?
Hi, if you could please help. Thanks. Here is the code
// ExploreDataService.swift
// tgkb
//
// Created by Jude on 2023/01/29.
//
import Foundation
class ExploreDataService {
static func getLocalData() -> [ExploreItems] {
let pathString = Bundle.main.path(forResource: "exploreData", ofType: "json")
guard pathString != nil else {
return [ExploreItems]()
}
let url = URL(fileURLWithPath: pathString!)
do {
let data = try Data(contentsOf: url)
let decoder = JSONDecoder()
do {
let exploreItems = try decoder.decode([ExploreItems].self, from: data)
for var p in exploreItems {
p.id = UUID()
}
return exploreItems
}
catch {
print("DEBUG: \(error)")
}
}
catch {
print("DEBUG: \(error)")
}
return [ExploreItems]()
}
}
my guess would be that it is this line let url = URL(fileURLWithPath: pathString!). Could you turn that in to a guard let instead of a force unwrap and see if the issue goes away?