Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
protocol EmailFormType {
// protocol definition goes here
}
protocol Printable {
// protocol definition goes here
}
protocol Selectable {
// protocol definition goes here
}
struct EmailItem: Printable, Selectable {
// structure definition goes here
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
var number: String
var expiration: String?
var month: String? { return "" }
var year: String? { return "" }
}
protocol Mockable {
static func mock(_ option: Int) -> Self
}
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 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
// 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
class Media {
var url: String
init(url: String) {
self.url = url
}
}
class Video: Media {
let mediaSet: [Media] = [Video(url: "http://[email protected]", thumb: "http://[email protected]"),
Video(url: "http://[email protected]", thumb: "http://[email protected]"),
Media(url: "http://[email protected]")]
for media in mediaSet {
// We don't sure about casting result
if let video = media as? Video {
print("Video: \(video)")
}