i have an array of class objects and i want to remove one of them at an specific index. The class contains simples variables. I tried to use the method removeAtIndex(index). But i am getting the error: Immutable value of type '[FieldData]' only has mutating members named 'removeAtIndex' I found that to solve this i should write mutating before the func of my method. But now i am getting the error: 'mutating' isn't valid on methods in classes or class-bound protocols
Can someone point me in the right direction to an answer, am i wrong in using a class for this? Or what is my problem here?
Thanks for the help.
general class definition:
class FieldData {
//string variables
init(variables) {
...
}
}
method definition
mutating func WandBestandEntf(fields: [FieldData]) -> [FieldData]? {
for var n = 0 as Int; n < fields.count; n++ {
if fields[n].name == "something" || fields[n].name == "other thing" {
fields.removeAtIndex(n)
}
}
}