ios – Swift – Why is ForEach/Checklist working just for some Arrays?

0
16
ios – Swift – Why is ForEach/Checklist working just for some Arrays?


I’ve a SwiftData Mannequin and not too long ago added a brand new Array which is holding “Sections” as Strings. It doesn’t matter what I attempt I am unable to make Swift to go trough this Array in any method utilizing ForEach, For or a Checklist. I at all times get this error:

Generic parameter 'V' couldn't be inferred

If I take advantage of one other Array tapas.asanas it really works flawlessly.

Right here is the Code Snippet, the error is proven on the Part(“Sections”) Line.

Part("Sections") {
    TextField("Add a brand new Part", textual content: $sectionName)
        .padding([.top, .bottom], 10)
    Button(motion: {
        tapas.tapasSections.append(sectionName)
        sectionName = ""
    }, label: {
        Textual content("Add Part")
    })
    
    Checklist(tapas.tapasSections) { identify in
        Textual content("(identify)")
    }
}

And right here is the SwiftData Mannequin:

import Basis
import SwiftData


@Mannequin
class Tapas {
    var identify: String
    
    /// Time Body of the Tapas
    var currentDay: Int
    var lengthInDays: Int = 21
    var lastDay: Date
    var startDay: Date = Date()
    
    var intention: String
    var intentionEvoked: Bool = false
    var guidelines: String = ""
    var supportTime: [Date] = []
    var tapasSections: [String] = []
    
    var recuperated: Bool
    var tapasType: String
    var isActive: String
    
    var recupType: String                   /// NoRecoup, TimedRecoup, UnlimitedRecoup for No recouperations, Recouperations earlier than Final Day, And even after
    var resetTime: Date
    
    var shade: String
    
    /// Including a relation to TapasAsana, as one Tapas has many Asanas
    @Relationship(deleteRule: .cascade) var asanas = [TapasAsana]()
    
    
    init(identify: String = "", intention: String = "", currentDay: Int = 1, lengthInDays: Int = 49, lastDay: Date = .now, recuperated: Bool = false, tapasType: String = "hatha", isActive: String = "dormant", recupType: String = "NoRecoup", resetTime: Date = .now, shade: String = "blue") {
        self.identify = identify
        self.intention = intention
        self.currentDay = currentDay
        self.lengthInDays = lengthInDays
        self.lastDay = lastDay
        self.recuperated = recuperated
        self.tapasType = tapasType
        self.isActive = isActive
        self.recupType = recupType
        self.resetTime = resetTime
        self.shade = shade
    }
}

As I stated earlier than, this relationship Array known as asanas is working in any ForEach or Checklist, additionally on this code above. Changing tapas.tapasSections with tapas.asanas resolves the error.

LEAVE A REPLY

Please enter your comment!
Please enter your name here