Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "Cannot invoke 'send' with no arguments" in Swift 5.1

I've been trying to follow the 'Introducing SwiftUI - Building Your First App' WWDC 19 video. No sample code is provided for this talk but I've been creating it as the presenter goes along. When trying to create a store though I get an error that 'Cannot invoke 'send' with no arguments' from the line:

didSet { didChange.send() }

I'm new to programming and struggling to troubleshoot.

import SwiftUI
import Combine

class ReferenceStore : BindableObject {
    var references: [Reference] {
        didSet { didChange.send() }
    }

    init(references: [Reference] = []) {
        self.references = references
    }

    var didChange = PassthroughSubject<Void, Never>()
}

I'm using Xcode 11 beta and MacOS Catalina if it helps.

like image 535
welshys Avatar asked Mar 04 '23 20:03

welshys


1 Answers

PassthroughSubject<Void, Never> is your publisher, and it's declared as:

final class PassthroughSubject<Output, Failure> where Failure : Error

And this is send function:

final func send(_ input: Output)

That means send needs a Void argument, which in Swift is the empty tuple ().

Replace:

didChange.send()

with

didChange.send(())

like image 79
Matteo Pacini Avatar answered May 14 '23 12:05

Matteo Pacini