This file contains 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 | |
protocol Fruit { | |
func getPrice() -> String | |
func getCount() -> Int | |
} | |
// Implements Fruit Protocol | |
class Orange: Fruit { | |
func getPrice() -> String { |
This file contains 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
// Abstract Factory | |
protocol FurnitureFactory { | |
static func createTable() -> Table | |
static func createChair() -> Chair | |
} | |
// Abstract product Table | |
protocol Table { | |
func count() -> Int |
This file contains 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 for creating a product | |
protocol ShoeShop { | |
func produceShoe() | |
} | |
// class that conforms to ShoeShop protocol | |
class Nike: ShoeShop { | |
func produceShoe() { | |
print("Shoe Produced") |
This file contains 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
// Singleton class Vehicle | |
class Vehicle { | |
static let sharedInstance = Vehicle() | |
// private initialser | |
private init() {} | |
func getName() -> String { | |
return "Car" | |
} |
This file contains 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
enum Level: Int { | |
case state = 1 | |
case national = 2 | |
case international = 3 | |
} | |
class Sports { | |
var level: Level | |
This file contains 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 Command { | |
func execute() | |
} | |
class ConcreteCommand: Command { | |
var colorReceiver: ColorReceiver | |
init(colorReceiver: ColorReceiver) { | |
self.colorReceiver = colorReceiver |
This file contains 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 MyBestFilms: Sequence { | |
let films: [String] | |
func makeIterator() -> MyBestFilmsIterator { | |
return MyBestFilmsIterator(films) | |
} | |
} | |
struct MyBestFilmsIterator: IteratorProtocol { |
This file contains 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 Receiver { | |
var name: String { get } | |
func receive(message: String) | |
} | |
protocol Sender { | |
var teams: [Receiver] { get set } | |
func send(message: String, sender: Receiver) | |
} |
This file contains 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
import UIKit | |
typealias MementoType = [String: Any] | |
protocol Memento: class { | |
var key: String { get set } | |
var state: MementoType { get set } | |
func save() |
This file contains 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 Observable { | |
func add(customer: Observer) | |
func remove(customer : Observer) | |
func notify() | |
} | |
protocol Observer { | |
var id: Int { get set } | |
func update() |