                         secret: token.core.secret,
                         algorithm: token.core.algorithm,
                         digits: token.core.digits
-                    )
+                    )!
                 )
             default: break
             }


    convenience override init() {
        // Stub an invalid token, to be replaced with a modified token via the setters
        self.init(token: Token(core: Generator(factor: .Timer(period: 30), secret: NSData())))
    }

    class func tokenWithType(type: OTPTokenType, secret: NSData, name: NSString, issuer:NSString) -> Self {
        switch type {
        case .Counter:
            return self(token: Token(name: name, issuer: issuer, core: Generator(factor: .Counter(0), secret: secret)))
        case .Timer:
            return self(token: Token(name: name, issuer: issuer, core: Generator(factor: .Timer(period: 30), secret: secret)))
        }
    }


                    secret: token.core.secret,
                    algorithm: newAlgorithm,
                    digits: token.core.digits
                )!
            )
        }
    }
