         return keychainItems.flatMap({ PersistentToken(keychainDictionary: $0) })
     }
 
+    // MARK: Write
+
+    /// Adds the given token to the keychain and returns the persistent token which contains it.
+    ///
+    /// - parameter token: The token to save to the keychain.
+    ///
+    /// - returns: The new persistent token, or `nil` if an error has occured.
     public func addToken(token: Token) -> PersistentToken? {
         guard let attributes = token.keychainAttributes,
             persistentRef = addKeychainItemWithAttributes(attributes) else {

        return PersistentToken(token: token, identifier: persistentToken.identifier)
    }

    // After calling deletePersistentToken(_:), the PersistentToken's identifier is no longer valid,
    // and the token should be discarded
    public func deletePersistentToken(persistentToken: PersistentToken) -> Bool {
        return deleteKeychainItemForPersistentRef(persistentToken.identifier)
    }


import Foundation

/// The `Keychain`'s shared instance is a singleton which represents the iOS system keychain used
/// to securely store tokens.
public final class Keychain {
    /// The singleton `Keychain` instance.
    public static let sharedInstance = Keychain()

    // MARK: Read

    /// Finds the persistent token with the given identifer, if one exists.
    ///
    /// - parameter token: The persistent identifier for the desired token.
    ///
    /// - returns: The persistent token, or `nil` if no token matched the given identifier.
    public func persistentTokenWithIdentifier(identifier: NSData) -> PersistentToken? {
        guard let result = keychainItemForPersistentRef(identifier) else {
            return nil
