Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
// 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
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
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")
}
}
protocol Mockable {
static func mock(_ option: Int) -> Self
}
struct Card: CardType {
var holderName: String
var number: String
var expiration: String?
var month: String? { return "" }
var year: String? { return "" }
}
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 }
}
protocol Printable {
// protocol definition goes here
}
protocol Selectable {
// protocol definition goes here
}
struct EmailItem: Printable, Selectable {
// structure definition goes here
protocol EmailFormType {
// protocol definition goes here
}
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 {
extension CreditCard {
subscript(index: Int) -> String? {
switch index {
case 0:
return number
case 1:
return date
case 2:
return name