Cannot invoke 'filter' with an argument list of type '((_) -> _)'

前端 未结 2 1370
挽巷
挽巷 2020-12-20 12:15

Sounds ridiculous, but I\'m unable to fix this piece of code:

self.runningScripts.filter({ $0 != scriptRunner })

No matter how I write the

相关标签:
2条回答
  • 2020-12-20 12:50

    I needed an explicit cast like this:

    @NSManaged private var storage: [String]
        private var  objects: Set<String>?
        func remove(element:String) {
            initSetIfNeeded()
            if(objects!.contains(element)) {
                objects!.remove(element)
                storage = storage.filter({($0 as NSObject) !== (element as NSObject)}) // Explicit cast here!!
            }
        }
    
    0 讨论(0)
  • 2020-12-20 13:02

    You can get that error if you didn't make ScriptRunner conform to Equatable:

    class ScriptRunner : Equatable {
        // the rest of your implementation here
    }
    
    func ==(lhs: ScriptRunner, rhs: ScriptRunner) -> Bool {
        return ... // change this to whatever test that satisfies that lhs and rhs are equal
    }
    
    0 讨论(0)
提交回复
热议问题