'In apples "displaying data in a list" swift ui tutorial I have the same code as the example with a different result
I copy pasted each line of code and still have different results then what is shown online.
I then downloaded Apple's completed project example and it ran properly.
How could the same code being copy and pasted not work but when just downloaded it worked fine?
I am trying to learn but I have been stuck on this for hours, I even put my code in a comparer and they are the exact same.
import SwiftUI
struct ScrumsView: View {
let scrums: [DailyScrum]
var body: some View {
List {
ForEach(scrums) { scrum in
NavigationLink(destination: Text(scrum.title)) {
CardView(scrum: scrum)
}
.listRowBackground(scrum.theme.mainColor)
}
}
.navigationTitle("Daily Scrums")
}
}
struct ScrumsView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
ScrumsView(scrums: DailyScrum.sampleData)
}
}
}
Theme code, it is not adding a folder with the colors atm
enum Theme: String {
case bubblegum
case buttercup
case indigo
case lavender
case magenta
case navy
case orange
case oxblood
case periwinkle
case poppy
case purple
case seafoam
case sky
case tan
case teal
case yellow
var accentColor: Color {
switch self {
case .bubblegum, .buttercup, .lavender, .orange, .periwinkle, .poppy, .seafoam, .sky, .tan, .teal, .yellow: return .black
case .indigo, .magenta, .navy, .oxblood, .purple: return .white
}
}
var mainColor: Color {
Color(rawValue)
}
var name: String {
rawValue.capitalized
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
