diff --git a/AdaptiveSpaceItem Example/macOS Example/Base.lproj/MainMenu.xib b/AdaptiveSpaceItem Example/macOS Example/Base.lproj/MainMenu.xib index 3dc70a7..a523da9 100644 --- a/AdaptiveSpaceItem Example/macOS Example/Base.lproj/MainMenu.xib +++ b/AdaptiveSpaceItem Example/macOS Example/Base.lproj/MainMenu.xib @@ -1,7 +1,7 @@ - + - + diff --git a/Sources/AdaptiveSpaceItem.swift b/Sources/AdaptiveSpaceItem.swift index 52c0c22..8bad0f7 100644 --- a/Sources/AdaptiveSpaceItem.swift +++ b/Sources/AdaptiveSpaceItem.swift @@ -47,10 +47,10 @@ public class AdaptiveSpaceItem: NSToolbarItem { private func minSize() -> NSSize { let items = toolbar?.items - let index = items?.indexOf(self) + let index = items?.index(of: self) guard let unwrappedIndex = index, - unwrappedItems = items, - superviewFrame = view?.superview?.frame where superviewFrame.origin.x > 0 else { + let unwrappedItems = items, + let superviewFrame = view?.superview?.frame, superviewFrame.origin.x > 0 else { return minSize } @@ -84,12 +84,17 @@ class AdaptiveSpaceItemView: NSView { // MARK: - Life cycle + override func awakeFromNib() { + super.awakeFromNib() + adaptiveSpaceItem?.updateWidth() + } + override func viewDidMoveToWindow() { - NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(windowDidResize), name: NSWindowDidResizeNotification, object: self.window) + NotificationCenter.default.addObserver(self, selector: #selector(windowDidResize), name: NSNotification.Name.NSWindowDidResize, object: self.window) } deinit { - NSNotificationCenter.defaultCenter().removeObserver(self) + NotificationCenter.default.removeObserver(self) } // MARK: - Notifications