0

When I want to assign a subscriber to a publisher I get this error:

No exact matches in call to instance method 'subscribe'

I write the code in ViewdidLoad:

let textPublisher = NotificationCenter.Publisher(center: .default, name: .labelChange).map({ ($0.object as! String) })
let textsubscriber = Subscribers.Assign(object: textLabel, keyPath: \.text)
textPublisher.subscribe(textsubscriber)
Raju Abe
  • 735
  • 2
  • 10
  • 25
gondor rad
  • 13
  • 1
  • 5

1 Answers1

1

Cast $0.object as optional.

.map({ ($0.object as? String)})

For .subscribe required the same type as .Publisher. But in your case publisher return string and subscriber return optional string so use optional in publisher to fix this issue.

enter image description here enter image description here

Raja Kishan
  • 16,767
  • 2
  • 26
  • 52