Maysam Maysam - 1 month ago 10
Swift Question

No 'flatMap' candidates produce the expected contextual result type

After converting my project to Swift 3.0 I face this error:


No 'flatMap' candidates produce the expected contextual result type AccessibilityAnnouncer.NotifierProducer' (aka 'SignalProducer<(), AccessibilityAnnouncer.NotificationError>')


This is the function:

fileprivate func createProducerForNotifier(_ announcement: String) -> NotifierProducer {
return NotificationCenter.defaultCenter.reactive.notifications(forName: NSNotification.Name.UIAccessibilityAnnouncementDidFinish, object: nil)
.map { $0.userInfo! }
.filter { ($0[UIAccessibilityAnnouncementKeyStringValue] as! String).isEqual(announcement) }
.take(1)
.promoteErrors(NotificationError)
.flatMap(.Merge) { userInfo -> NotifierProducer in
let success = userInfo[UIAccessibilityAnnouncementKeyWasSuccessful]!.boolValue!

if (success) {
return .empty
} else {
return SignalProducer(error: .AnnouncementFailed)
}
}
}

Answer

In Swift 3.0 you have to import ReactiveSwift as well.