Posts

Post not yet marked as solved
5 Replies
2.6k Views
Hi,I am working with SwiftUI, and am new to Xcode, and Swift at all.I did the SwiftUI essentials Tutorial, and done the Controls and Views part.Now I am stuck on my own creation app.I try to get data from an local .json file which I stored in the Resources folder.In the preview View, I pass in the data of index 0, but while rendering the preview it always crashes, and cannot build a preview.I almost copied all the files from the BuildingListsAndNavigations project.This is my View where I try to post from the json fileimport SwiftUI struct UserRow : View { var user: User var body: some View { Text(user.name) } } #if DEBUG struct UserRow_Previews : PreviewProvider { static var previews: some View { UserRow(user: userData[0]) } } #endifhere is the data.swift fileimport UIKit import SwiftUI import CoreLocation let userData: [User] = load("users.json") func load<T: Decodable>(_ filename: String, as type: T.Type = T.self) -> T { let data: Data guard let file = Bundle.main.url(forResource: filename, withExtension: nil) else { fatalError("Couldn't find \(filename) in main bundle.") } do { data = try Data(contentsOf: file) } catch { fatalError("Couldn't load \(filename) from main bundle:\n\(error)") } do { let decoder = JSONDecoder() return try decoder.decode(T.self, from: data) } catch { fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)") } }Why does it crash? Did I miss something?
Posted
by eren93.
Last updated
.
Post not yet marked as solved
0 Replies
391 Views
Hi, I enrolled the Developer program and installed the Developer profile so I could get the Beta Versions.So I did and it worked. But now I need to update my OS to beta 7. But it won't work. It gives me a warning. Says something like Update not found or couldn't be installed.Later it says it is already up-to-date. But its not. I checked the build number.Thanks in advance
Posted
by eren93.
Last updated
.