So I have the following partial function implementation:
func addObserver(with notificationType: String) -> (@escaping (Notification) -> (Void)) -> NSObjectProtocol
{
return { (function: @escaping (Notification) -> (Void)) in
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: notificationType), object: nil, queue: nil, using: function)
}
}
Which basically would be used as such to create a full function such as:
let aoSelectCountry = addObserver(with: selectCountryNotification)
Which would then be used as:
self.selectCountryObserver = aoSelectCountry{ (notification) in
if (notification.object != nil) {
//do things
}
}
This is effectively the same as writing:
self.selectCountryObserver = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: selectCountryNotification), object: nil, queue: nil) { (notification) in
if (notification.object != nil) {
//do things
}
Now all of this worked in XCode 8. But when I try to compile in XCode 9, I get the following error:
Cannot convert value of type '(Notification) -> (Void)' to expected argument type '(Notification) -> Void'
Removing the brackets around the (Void) part of the initial function just changes the error message to:
Cannot convert value of type '(Notification) -> Void' to expected argument type '(Notification) -> Void'
I have a strong feeling that this is a compiler bug, but I do desperately need a work around. I appreciate anyone's efforts. Thanks!