that is also appearing when I click the "I" button in the preview error banner
I am attempting to use the SwiftUI tutorial at https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation (section 2)
here is the code for the view that the preview is "crashing" on:
import SwiftUI
struct LandmarkRow: View {
var landmark: Landmark
var body: some View {
HStack {
landmark.image
.resizable()
.frame(width: 50, height: 50)
Text("landmark.name")
Spacer()
}
}
}
struct LandmarkRow_Previews: PreviewProvider {
static var previews: some View {
LandmarkRow(landmark: landmarks[0])
}
}
Here is the code for the area it is having the problem:
import Foundation
var landmarks: [Landmark] = load("landmarkDelta.json")
func load<T: Decodable>(_ filename: String) -> 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)")
}
}
It is saying there is an error on line 17. Here is the line of code:
fatalError("Couldn't find (filename) in main bundle.")
Here is the code from the Tutorial:
import Foundation
var landmarks: [Landmark] = load("landmarkData.json")
func load<T: Decodable>(_ filename: String) -> 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)")
}
}
does anyone know what's wrong and how to fix it?
Post
Replies
Boosts
Views
Activity
Hello! I am a new developer learning Swift and Xcode for the first time and I am using the tutorial here: https://developer.apple.com/tutorials/swiftui/creating-and-combining-views
Now, for no reason its telling me "Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project"
I am using Xcode Version 13.4.1 (13F100)
Here is the code
//
// ContentView.swift
// Landmarks
//
// Created by [name] on 6/26/22.
//
import SwiftUI
struct ContentView: View {
var body: some View { Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
VStack (alignment: .leading){
Text("Turtle Rock")
.font(.title)
.foregroundColor(.black)
HStack {
Text("Joshua Tree National Park").font(.subheadline)
Spacer()
Text("California").font(.subheadline)
}
}
.padding
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Hello! I am trying to learn to make apps with Swift Playgrounds and Swift UI. The devices I own include an iPad Air 4 running iPadOS 15, M1 Mac Mini running macOS Monterey, iPhone 13 running iOS 15, and an Apple Watch Series 4 running WatchOS 8. I plan to update all of these devices to the next-gen public betas as they release.
Ive completed the “Getting Started with Apps” course on Swift Playgrounds on my iPad.
does anyone have any tips on starting from scratch, or know how I can learn more and sharpen my skills?
thank you!