     }
     
     public override func ubiquityStateDidChange(oldState: UbiquityState, newState: UbiquityState) {
-        if oldState == .Available && newState != .Available {
+        switch newState {
+        case .Disabled:
             self.keyValueStore = nil
-        } else if oldState != .Available && newState == .Available {
+        default:
             self.keyValueStore = NSUbiquitousKeyValueStore.defaultStore()
         }
     }

        didSet {
            if let keyValueStore = self.keyValueStore {
                NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(KeyValueUbiquityContainer.nsUbiquitiousKeyValueStoreDidChangeExternally(_:)), name: NSUbiquitousKeyValueStoreDidChangeExternallyNotification, object: keyValueStore)
                if !keyValueStore.synchronize() {
                    Logger.log(.Error, message: "Failed to synchronize Ubiquitious Key Value Store", error: nil, type: self.dynamicType)
                }
            }
        }
    }

    func didSetUserDefault(userDefault: UserDefault, forKey key: String)
}

/// ### KeyValueUbiquityContainer
/// A subclass of `UbiquityContainer` that manages access to a `NSUbiquitousKeyValueStore` instance.
public class KeyValueUbiquityContainer: UbiquityContainer {
    public struct Keys {
        static let value = "value"
