Structure
DSCreditCard
public struct DSCreditCard
A credit card that identifies properties of various brand types, performs validation, and can perform formatting of their numbers.
let creditCard = DSCreditCard(number: "4111111111111111")
print(creditCard.isValid)
print(creditCard.formattedNumber)
Initializers
init(number:)
public init(number: String)
Initializes and returns a newly allocated CreditCard based on the number.
Parameters
Name | Type | Description |
---|---|---|
number | String |
A credit card number |
Properties
cardType
public private(set) var cardType: DSCreditCardType
The type of credit card, identified as best as possible, based on a number.
isValid
public var isValid: Bool
Returns true if the card number's brand is identifiable, and valid to those constraints, or if the brand is not identified and has a length greater than 0.
formattedNumber
public var formattedNumber: String
Returns the properly formatted card number if its brand is identified. (e.g. Visa, Mastercard, etc.)