     
     class var defaults: NSUserDefaults {get {return NSUserDefaults.standardUserDefaults()}}
     
-    init(appVersion: String?, buildNumber: String?) {
+    public init(appVersion: String?, buildNumber: String?) {
         self.appVersion = appVersion
         self.buildNumber = buildNumber
     }


import Foundation

class RGAppVersion {
    
    enum RGAppVersionState {
        case NotDetermined, Installed, Updated, NothingChanged
    }
    
    static let lastInstalledAppVersionKey = "rg.appVersion.lastInstalledAppVersion"
    static let lastInstalledBuildKey = "rg.appVersion.lastInstalledAppversion"
    
    private static var _lastInstalledAppVersion: RGAppVersion?
    private static var _currentAppVersion: RGAppVersion?
    static var appVersionState = RGAppVersionState.NotDetermined
    
    var appVersion: String?
    var buildNumber: String?
    
    var combinedVersion: String {
        get {
            if let appVersion = appVersion, buildNumber = buildNumber {
                return "\(appVersion)(\(buildNumber))"

        if _lastInstalledAppVersion?.appVersion == nil {
            _currentAppVersion?.setAsCurrentVersion()
            
            _appVersionState = .Installed
        }
        // App updated.
        else if _lastInstalledAppVersion?.combinedVersion != _currentAppVersion?.combinedVersion {
            _currentAppVersion?.setAsCurrentVersion()
            
            _appVersionState = .Updated
        }
        // Nothing changed.
        else {
            _appVersionState = .NothingChanged
        }
    }
    
    public class func currentVersion() -> RGAppVersion {
        if _appVersionState == .NotDetermined {
            RGAppVersion.determineAppVersionState()
        }
        return _currentAppVersion!
    }
    
    public class func lastVersion() -> RGAppVersion? {
        if _appVersionState == .NotDetermined {
            RGAppVersion.determineAppVersionState()
        }
        return (_lastInstalledAppVersion?.appVersion == nil) ? nil : _lastInstalledAppVersion
    }
    
    public class func appIsFreshInstalled() -> Bool {
        if _appVersionState == .NotDetermined {
            RGAppVersion.determineAppVersionState()
        }
        return _appVersionState == .Installed
    }
    
    public class func appWasUpdated() -> Bool {
        if _appVersionState == .NotDetermined {
            RGAppVersion.determineAppVersionState()
        }
        return _appVersionState == .Updated
    }
}
