Skip to content

Commit

Permalink
Fix #2 preferences tab view controller if first selected tab implemen…
Browse files Browse the repository at this point in the history
…t the protocol

to not remove observer if not added (try catch unavailable in swift 1)
  • Loading branch information
phimage committed Jul 30, 2015
1 parent f6d1e39 commit 834f4ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Prephirences.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pod::Spec.new do |s|

# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.name = "Prephirences"
s.version = "1.2.1"
s.version = "1.2.2"
s.summary = "A Swift library to manage preferences"
s.description = <<-DESC
Prephirences is a Swift library that provides useful protocols and methods to manage preferences.
Expand Down
5 changes: 4 additions & 1 deletion PrephirencesMacOSX/PreferencesTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public let kPreferencesTabViewSize = "preferencesTabViewSize"

/* Controller which resize parent window according to tab view items, useful for preferences */
public class PreferencesTabViewController: NSTabViewController {
private var observe = false

// Keep size of subview
private var cacheSize = [NSView: NSSize]()
Expand All @@ -51,8 +52,9 @@ public class PreferencesTabViewController: NSTabViewController {
override public func tabView(tabView: NSTabView, willSelectTabViewItem tabViewItem: NSTabViewItem) {
// remove listener on previous selected tab view
if let selectedTabViewItem = self.selectedTabViewItem as? NSTabViewItem,
viewController = selectedTabViewItem.viewController as? PreferencesTabViewItemControllerType {
viewController = selectedTabViewItem.viewController as? PreferencesTabViewItemControllerType where observe {
(viewController as! NSViewController).removeObserver(self, forKeyPath: kPreferencesTabViewSize, context: nil)
observe = false
}

super.tabView(tabView, willSelectTabViewItem: tabViewItem)
Expand All @@ -67,6 +69,7 @@ public class PreferencesTabViewController: NSTabViewController {
// Observe kPreferencesTabViewSize
let options = NSKeyValueObservingOptions.New | NSKeyValueObservingOptions.Old
(viewController as! NSViewController).addObserver(self, forKeyPath: kPreferencesTabViewSize, options: options, context: nil)
observe = true
}
else {
cacheSize[view] = cacheSize[view] ?? currentSize
Expand Down

0 comments on commit 834f4ec

Please sign in to comment.