Ben Stock
Ben Stock

Reputation: 2026

Swift 3 Refactoring: "Type 'NSView' has no member ..." Error

Before Swift 3, I created a private extension of Selector in my NSRulerView subclass that looked like this:

private extension Selector {
    static let shouldAddMarker = #selector(NSView.rulerView(_:shouldAdd:shouldAddMarker:))
    static let willAddMarker = #selector(NSView.rulerView(_:willAdd:atLocation:willAddMarker:atLocation:))
    static let didAddMarker = #selector(NSView.rulerView(_:didAdd:didAddMarker:))
}

This was convenient because I could simply use my private short member names to access a selector, like so:

if self.delegate?.respondsToSelector(.shouldAddMarker) == true {
    // I have a delegate and it conforms to the NSRulerMarkerClientViewDelegation protocol.
}

Now that I'm desperately trying to convert my existing Swift codebase to 3.0, NSView doesn't seemingly implement the aforementioned methods.

I know that NSRulerMarkerClientViewDelegation is an informal protocol, and its declared methods are implemented as an extension to NSView, but I don't see any API changes from Swift 2.x to 3.0 that would break my existing selectors.

Does anyone have a clue as to where I should go from here? Any advice would be greatly appreciated.

Upvotes: 1

Views: 197

Answers (1)

vacawama
vacawama

Reputation: 154603

Here are the new selectors for Swift 3:

private extension Selector {
    static let shouldAddMarker = #selector(NSView.rulerView(_:shouldAdd:))
    static let willAddMarker = #selector(NSView.rulerView(_:willAdd:atLocation:))
    static let didAddMarker = #selector(NSView.rulerView(_:didAdd:))
}

Upvotes: 3

Related Questions