WAAccountStore 1.3

WAAccountStore 1.3

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Feb 2016

Maintained by YuAo.



 
Depends on:
WAKeyValuePersistenceStore>= 0
UICKeyChainStore>= 0
 

  • By
  • YuAo

WAAccountStore is a simple yet extensible account system.

It encapsulates the basic account management functions, the security storage of the account credential. And allows you to store any useful information you want with a account.

Infrastructure

WAAccount represents a user account. It contains a WAAccountCredential for storing account credential info and a user info object for storing additional info.

WAAccountCredential provides a secure way of storing account credentials. It has a securityStorage property. Anything in the securityStorage will be stored safely in the keychain.

WAAccountStore provides a set of account management functions, such as add account, remove account, update account, etc. As well as notifications for account change (WAAccountStoreCurrentAccountDidChangeNotification, WAAccountStoreCurrentAccountUpdatedNotification)

Usage

Use the default store throughout your app.

WAAccountStore.defaultStore()

You may start using WAAccountStore directly. However creating some simple extensions for WAAccountCredential and WAAccount will make your life easier.

For example:

Associate your user model with WAAccount.

//Assuming `User` is your user model class.
extension WAAccount {
    var user: User {
        get {
            return self.userInfo as! User
        }
    }

    convenience init(identifier: String, credential: WAAccountCredential, user: User) {
        self.init(identifier: identifier, credential: credential, userInfo: user)
    }
}

Direct access to securityStorage of WAAccountCredential is inconvenient. Create a extension for convenient access.

let UserAccessTokenStorageKey = "AccessToken"

extension WAAccountCredential {
    var accessToken: String {
        get {
            return self.securityStorage[UserAccessTokenStorageKey] as! String
        }
    }

    convenience init(identifier: String, accessToken: String) {
        self.init(identifier: identifier, securityStorage: [UserAccessTokenStorageKey: accessToken])
    }
}

Demo

There's a simple demo project in WAAccountStoreDemo folder. A pod install is required to open and build WAAccountStoreDemo.xcworkspace

Install

Either clone the repo and manually add the files in WAAccountStore directory

or if you use Cocoapods, add the following to your Podfile

pod 'WAAccountStore'

Note

WAAccountStore makes use of WAKeyValuePersistenceStore and UICKeyChainStore

Requirements

  • Automatic Reference Counting (ARC)
  • iOS 7.0+
  • Xcode 6.3+