Can anyone suggest how to solve this NSCollectionView
issue? Converted from Swift 3 to Swift 4 and magic started happening :)
Code:
let item = NSNib(nibNamed: NSNib.Name(rawValue: "MACollectionViewItem"), bundle: nil)
collectionView.register(item, forItemWithIdentifier: "CollectionViewItem")
Error for the second line:
Cannot invoke '
register
' with an argument list of type'(NSNib?, forItemWithIdentifier: String)'
In Swift 4, you need to use NSUserInterfaceItemIdentifier
instead of a String
to identify a user interface element.
You should define static constants for identifiers and reference them when registering nibs.
Example:
extension NSUserInterfaceItemIdentifier {
static let collectionViewItem = NSUserInterfaceItemIdentifier("CollectionViewItem")
}
collectionView.register(item, forItemWithIdentifier: .collectionViewItem)