SwiftData erors in Swift Playground

Hi, I want to add a SwiftData model to my Swift Playground in Xcode 15.2, but I get errors related to iOS version, has anyone encountered this? Thanks

import Foundation
import SwiftData

struct testStruct: Identifiable {
    let id = UUID()
    var question: String
    var answer: String
}

@Model
class testClass: Identifiable {
    let id = UUID()
    var question1: testStruct
    var question2: testStruct
    var question3: testStruct
    var question4: testStruct
    var question5: testStruct
    
    init(question1: testStruct, question2: testStruct, question3: testStruct, question4: testStruct, question5: testStruct) {
        self.question1 = question1
        self.question2 = question2
        self.question3 = question3
        self.question4 = question4
        self.question5 = question5
    }
}

Accepted Reply

Hi! SwiftData is a framework available in iOS 17 or newer.

By default, it seems that App Playgrounds default to iOS 16 support in Xcode. The App you will submit to the Swift Student Challenge will need to run on iOS 16 or newer as explained on this thread, but if you want to add iOS 17-specific behaviour, you could use the if #available version check or the @available(iOS 17.0, *) attribute as explained in this other thread.

Do not change the minimum deployment version in the Package.swift mentioned in the latter thread! As I previously said, the minimum version should be iOS 16 for 2024 Swift Student Challenge submissions.

Replies

Hi! SwiftData is a framework available in iOS 17 or newer.

By default, it seems that App Playgrounds default to iOS 16 support in Xcode. The App you will submit to the Swift Student Challenge will need to run on iOS 16 or newer as explained on this thread, but if you want to add iOS 17-specific behaviour, you could use the if #available version check or the @available(iOS 17.0, *) attribute as explained in this other thread.

Do not change the minimum deployment version in the Package.swift mentioned in the latter thread! As I previously said, the minimum version should be iOS 16 for 2024 Swift Student Challenge submissions.