0

I have Struct init and I'm trying to filter the an array in init:

public struct doSomething: Codable {
    public var listOfStuff: [String]

    init(someStuff: [String]) {
        var clone = someStuff
        let stuff: [String] = clone.removeAll { $0 == "myName"}
        listOfStuff = stuff
    }
}

On this line let stuff: [String] = clone.removeAll { $0 == "myName"} I'm getting this error:

error: cannot convert value of type '()' to specified type '[String] enter image description here Any of you knows why I'm getting this error or if you know a work around?

I'll really appreciate your help.

user2924482
  • 8,380
  • 23
  • 89
  • 173

1 Answers1

3

removeAll does not return a value. That's the same thing as returning Void, which is the same thing as ().

clone.removeAll { $0 == "myName" }
listOfStuff = clone

Better yet, don't even use it.

init(someStuff: [String]) {
  listOfStuff = someStuff.filter { $0 != "myName" }
}