Kex
Kex

Reputation: 8609

Trouble adding observer to NotificationCenter in Swift 3.0

I'm having trouble adding a notification observer in Swift 3.0.

Code like so:

NotificationCenter.default.addObserver(self, selector: .playerItemDidPlayToEndTime, name: Notification.Name(AVPlayerItemDidPlayToEndTimeNotification), object: playerItem)

I am getting the error: "Cannot invoke value of type Notification.Name.type (aka NSNotification.Name.Type) with argument list (NSNotification.Name)"

With:

AVF_EXPORT NSString *const AVPlayerItemDidPlayToEndTimeNotification      NS_AVAILABLE(10_7, 4_0);

What am I doing wrong here?

Upvotes: 1

Views: 915

Answers (2)

TheEye
TheEye

Reputation: 9346

Not in this case but also important: you need to import AVFoundation in your file. In Swift the imports are mostly not necessary anymore, so I tend to forget them when needed ...

Upvotes: 0

Dharmesh Kheni
Dharmesh Kheni

Reputation: 71854

As Martin R Commented, name argument should be:

NSNotification.Name.AVPlayerItemDidPlayToEndTime

And complete code will be:

NotificationCenter.default.addObserver(self, selector: .playerItemDidPlayToEndTime, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playerItem)

Upvotes: 1

Related Questions