Scrumdinger, Create the Card View

Hi! I'm learning Swift from Apples Tutorials. Right now I'm doing the Scrumdinger tutorial and I'm following the steps to create the app. But right now I get the following errors when I'm creating the CardView.

  1. Static property 'sampleData' is not a member type of 'DailyScrum'
  2. Array types are now written with the brackets around the element type

This is my code:

import Foundation



struct DailyScrum {

    var title: String

    var attendees: [String]

    var lengthInMinutes: Int

    var theme: Theme

}



extension DailyScrum {

    static let sampleData: [DailyScrum] = [

        DailyScrum(title: "Design", attendees: ["Chris, Hans"], lengthInMinutes: 10, theme: .yellow),

        DailyScrum(title: "Frontend", attendees: ["Daniel, Maria"], lengthInMinutes: 10, theme: .yellow),

        DailyScrum(title: "Backend", attendees: ["Fred, Helen"], lengthInMinutes: 10, theme: .yellow)

    ]

}
import SwiftUI



struct CardView: View {

    let scrum: DailyScrum

    var body: some View {

        Text("Hello, World!")

    }

}



struct CardView_Previews: PreviewProvider {

    static var scrum: DailyScrum.sampleData[0]

    static var previews: some View {

        CardView(scrum: scrum)

    }

}

Has the language changed since the tutorial was written? Any advice on how I shall proceed?

Best regards, Fredrik

Are you sure you copied exactly the tutorial code ? You should not declare in extension.

Try with this:

struct DailyScrum {
    var title: String
    var attendees: [String]
    var lengthInMinutes: Int
    var theme: Theme
    var sampleData: [DailyScrum] = [
        DailyScrum(title: "Design", attendees: ["Chris, Hans"], lengthInMinutes: 10, theme: .yellow),
        DailyScrum(title: "Frontend", attendees: ["Daniel, Maria"], lengthInMinutes: 10, theme: .yellow),
        DailyScrum(title: "Backend", attendees: ["Fred, Helen"], lengthInMinutes: 10, theme: .yellow)
    ]
}

Thank you so much for answering, I will try adding the sampleData inside the struct instead. But it's quite funny since this is what the code from the tutorial.

import Foundation

struct DailyScrum {
    var title: String
    var attendees: [String]
    var lengthInMinutes: Int
    var theme: Theme
}

extension DailyScrum {
    static let sampleData: [DailyScrum] =
    [
        DailyScrum(title: "Design", attendees: ["Cathy", "Daisy", "Simon", "Jonathan"], lengthInMinutes: 10, theme: .yellow),
        DailyScrum(title: "App Dev", attendees: ["Katie", "Gray", "Euna", "Luis", "Darla"], lengthInMinutes: 5, theme: .orange),
        DailyScrum(title: "Web Dev", attendees: ["Chella", "Chris", "Christina", "Eden", "Karla", "Lindsey", "Aga", "Chad", "Jenn", "Sarah"], lengthInMinutes: 5, theme: .poppy)
    ]
}

If you look at the complete code, extension works as proposed. https://github.com/ashwinkey04/scrumdinger-ios

The difference is that there is an init in the struct:

import Foundation

struct DailyScrum: Identifiable {
    let id: UUID
    var title: String
    var attendees: [Attendee]
    var lengthInMinutes: Int
    var theme: Theme
    var history: [History] = []
    
    init(id: UUID = UUID(), title: String, attendees: [String], lengthInMinutes: Int, theme: Theme) {
        self.id = id
        self.title = title
        self.attendees = attendees.map { Attendee(name: $0) }
        self.lengthInMinutes = lengthInMinutes
        self.theme = theme
    }
}

extension DailyScrum {
    struct Attendee: Identifiable {
        let id: UUID
        var name: String
        
        init(id: UUID = UUID(), name: String) {
            self.id = id
            self.name = name
        }
    }
    
    struct Data {
        var title: String = ""
        var attendees: [Attendee] = []
        var lengthInMinutes: Double = 5
        var theme: Theme = .seafoam
    }
    
    var data: Data {
        Data(title: title, attendees: attendees, lengthInMinutes: Double(lengthInMinutes), theme: theme)
    }
    
    mutating func update(from data: Data) {
        title = data.title
        attendees = data.attendees
        lengthInMinutes = Int(data.lengthInMinutes)
        theme = data.theme
    }
    
    init(data: Data) {
        id = UUID()
        title = data.title
        attendees = data.attendees
        lengthInMinutes = Int(data.lengthInMinutes)
        theme = data.theme
    }
}

extension DailyScrum {
    static let sampleData: [DailyScrum] =
    [
        DailyScrum(title: "Design", attendees: ["Cathy", "Daisy", "Simon", "Jonathan"], lengthInMinutes: 10, theme: .yellow),
        DailyScrum(title: "App Dev", attendees: ["Katie", "Gray", "Euna", "Luis", "Darla"], lengthInMinutes: 5, theme: .orange),
        DailyScrum(title: "Web Dev", attendees: ["Chella", "Chris", "Christina", "Eden", "Karla", "Lindsey", "Aga", "Chad", "Jenn", "Sarah"], lengthInMinutes: 5, theme: .poppy)
    ]
}
Scrumdinger, Create the Card View
 
 
Q