diff --git a/SwiftLuhn/Classes/SwiftLuhn.swift b/SwiftLuhn/Classes/SwiftLuhn.swift index 3495f8a..23be076 100644 --- a/SwiftLuhn/Classes/SwiftLuhn.swift +++ b/SwiftLuhn/Classes/SwiftLuhn.swift @@ -19,6 +19,16 @@ open class SwiftLuhn { case maestro case rupay case mir + + static var allCards: [CardType] { + var values: [CardType] = [] + var index = 1 + while let element = self.init(rawValue: index) { + values.append(element) + index += 1 + } + return values + } } public enum CardError: Error { @@ -116,8 +126,7 @@ open class SwiftLuhn { class func cardType(for cardNumber: String, suggest: Bool = false) throws -> CardType { var foundCardType: CardType? - for i in CardType.amex.rawValue...CardType.jcb.rawValue { - let cardType = CardType(rawValue: i)! + for cardType in CardType.allCards { let regex = suggest ? suggestionRegularExpression(for: cardType) : regularExpression(for: cardType) let predicate = NSPredicate(format: "SELF MATCHES %@", regex)