Created
October 15, 2018 03:41
-
-
Save vialyx/73794114330a601a12d66715616d64f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CreditCard { | |
subscript(index: Int) -> String? { | |
switch index { | |
case 0: | |
return number | |
case 1: | |
return date | |
case 2: | |
return name | |
case 3: | |
return ccv | |
default: | |
return nil | |
} | |
} | |
} | |
let subscriptCard = CreditCard(number: "4111 0000 2345 0000", date: "03/20", ccv: "243") | |
print("card number: \(String(describing: subscriptCard[0]))") | |
// Optional("4111 0000 2345 0000") | |
print("card date: \(String(describing: subscriptCard[1]))") | |
// Optional("03/20") | |
print("card name: \(String(describing: subscriptCard[2]))") | |
// Optional("") | |
print("card ccv: \(String(describing: subscriptCard[3]))") | |
// Optional("243") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment