Fabrizio Bartolomucci Fabrizio Bartolomucci - 1 year ago 90
iOS Question

Very funny error on Xcode 8.0 beta 3 in accessing function from notifications and timers

I am getting this very strange and rather mocking error from Xcode:
Funny Error Message
While executing:

NotificationCenter.default.addObserver(self, selector:#selector(Booking.loadElement(_:)), name:String(format:"portal%d", portalIdent), object:nil)


Timer(timeInterval:5, target:self, selector:#selector(Booking.bookingTimerMethod(_:)), userInfo:"load", repeats:false).fire()

As you see the compiler complaints the functions not to exist and suggest me to use the same functions!

What is this and how may I make up for it?

Answer Source

The reason was simply due to the fact I forgot to add parameter 'notification:'.

NotificationCenter.default.addObserver(self, selector:#selector(Booking.loadElement(notification:)), name:NSNotification.Name(rawValue: String(format:"portal%d", portalIdent!)), object:nil)

Works just fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download