Skip to content

Instantly share code, notes, and snippets.

protocol Subsciber: AnyObject {
func update()
}
class Publisher {
static let shared = Publisher()
private lazy var subscribers = [Subsciber]()
import Foundation
// Overloaded function - Same name but different signatures
func addition(_ operand1: Int, operand2: Int) -> Int {
return 0
}
// When a function returnes nothing == void()
@OyegokeTomisin
OyegokeTomisin / Wednesday
Last active April 1, 2021 09:11
Week 1 - Morning Session
import Foundation
enum Apperance {
case lightMode
case darkMode
case orangeMode
}
class Houses {
@OyegokeTomisin
OyegokeTomisin / Tuesday.playground
Last active March 31, 2021 15:41
Tuesday's QnA
import Foundation
// MARK:- Extensions
let tomiNumber: String = "08080008009"
let car = "toyota"
extension String {
enum TransactionType: String, Codable{
case debit
case credit
case unknown
init(from decoder: Decoder) throws {
guard let value = try? decoder.singleValueContainer().decode(String.self) else{
self = .unknown
return
}
private func displayTransactionStatus() {
if let transactionList = getTransactionData()?.data{
transactionList.forEach({ transaction in
switch transaction.type{
case .credit:
print("🤑")
case .debit:
print("😓")
case .unknown:
print("🤷🏽‍♂️")
class ViewController: UIViewController {
private var transactionData: TransactionData?
override func viewDidLoad() {
super.viewDidLoad()
displayTransactionStatus()
}
private func getTransactionData() -> TransactionData? {
enum TransactionType: String, Codable{
case debit
case credit
}
struct TransactionData: Codable {
let data: [Transaction]
}
struct Transaction: Codable {
struct TransactionData: Codable {
let data: [Transaction]
}
struct Transaction: Codable {
var id: String?
var type: TransactionType?
enum CodingKeys: String, CodingKey {
case id = "_id"
{
"data": [
{
"type" : "credit",
"_id" : "123abc"
},
{
"type" : "debit",
"_id" : "123def"
},