maxkramer / SwiftLuhn

Debit/Credit card validation port of the Luhn Algorithm in Swift
MIT License
135 stars 27 forks source link

Card type detection fixed #19

Open nagarro-mohitpadalia opened 5 years ago

nagarro-mohitpadalia commented 5 years ago

Hi @maxkramer

The PR fixes the issue #18

The caseIterable protocol works for enumerations without associated values, so I have added a simple solution to get the count of all enum cases:

Please review.

maxkramer commented 5 years ago

@nagarro-mohitpadalia thanks a lot for your support! That's a good find, and I'm surprised that the CaseIterable doesn't support enum int associated values, as enums are usually integer based already.

I think it would probably be better to use something along the lines of the following to ensure that we don't have an issue in the future with adding additional cases and forgetting to update the count variable. This loops through 1..n to calculate all cases. What are your thoughts?

https://gist.githubusercontent.com/polac24/f33791151e22d4787a09262d66f01bcd/raw/8ea9e37fae685fb9f21fbbbfaa601e51f2b927af/IntEnum.swift

Stolen from: https://medium.com/@londeix/listing-all-cases-in-an-enum-3b057f2c1432

nagarro-mohitpadalia commented 5 years ago

@maxkramer

I have done the suggested change you can review and merge.

maxkramer commented 5 years ago

@nagarro-mohitpadalia that's great, thanks a lot for your support! Just waiting for CI, and will then get that merged!

maxkramer commented 5 years ago

@nagarro-mohitpadalia circleci have removed our free plan for Mac OSX builds, currently waiting for them to renew it. Will merge thereafter.

maxkramer commented 5 years ago

@nagarro-mohitpadalia CircleCI have now fixed the issue. Please could you push the commit again / push a blank commit to trigger the CI build?

nagarro-mohitpadalia commented 5 years ago

@maxkramer I have pushed dummy commits, hope this will trigger the CI build