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
// enable entities to be used within any source file from their defining module, and also in a source file from another module that imports the defining module. | |
public var publicVariable = 0 | |
// enables entities to be used within any source file from their defining module, but not in any source file outside of that module. | |
internal let internalConstant = 1 | |
// access restricts the use of an entity to its own defining source file. | |
fileprivate var fileprivateVariable = 2 | |
// restricts the use of an entity to the enclosing declaration, and to extensions of that declaration that are in the same file. | |
private let privateConstant = 3 |
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
protocol CardType { | |
var holderName: String { get set } | |
var number: String { get set } | |
var expiration: String? { get set } | |
var month: String? { get } | |
var year: String? { get } | |
} | |
struct Card: CardType { | |
var holderName: String |
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 Card: Mockable { | |
static func mock(_ option: Int) -> Card { | |
switch option { | |
case 1: | |
return Card(holderName: "John Malkovich", number: "4111 1111 1111 1111", expiration: "09/12") | |
default: | |
return Card(holderName: "Mock", number: "0000 0000 0000 0000", expiration: "00/00") | |
} | |
} |
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
protocol Mockable { | |
static func mock(_ option: Int) -> Self | |
} |
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
struct Card: CardType { | |
var holderName: String | |
var number: String | |
var expiration: String? | |
var month: String? { return "" } | |
var year: String? { return "" } | |
} |
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
protocol CardType { | |
var holderName: String { get set } | |
var number: String { get set } | |
var expiration: String? { get set } | |
var month: String? { get } | |
var year: String? { get } | |
} |
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
protocol Printable { | |
// protocol definition goes here | |
} | |
protocol Selectable { | |
// protocol definition goes here | |
} | |
struct EmailItem: Printable, Selectable { | |
// structure definition goes here |
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
protocol EmailFormType { | |
// protocol definition goes here | |
} |
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 { | |
enum CardType { | |
case visa, unknown | |
} | |
var type: CardType { | |
guard number.count >= 1 else { return .unknown } | |
let firstNumber = number[number.startIndex..<number.index(number.startIndex, offsetBy: 1)] | |
switch firstNumber { |
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 |