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 Subsciber: AnyObject { | |
| func update() | |
| } | |
| class Publisher { | |
| static let shared = Publisher() | |
| private lazy var subscribers = [Subsciber]() | |
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
| import Foundation | |
| // Overloaded function - Same name but different signatures | |
| func addition(_ operand1: Int, operand2: Int) -> Int { | |
| return 0 | |
| } | |
| // When a function returnes nothing == void() |
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
| import Foundation | |
| enum Apperance { | |
| case lightMode | |
| case darkMode | |
| case orangeMode | |
| } | |
| class Houses { |
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
| import Foundation | |
| // MARK:- Extensions | |
| let tomiNumber: String = "08080008009" | |
| let car = "toyota" | |
| extension 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
| 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 | |
| } |
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
| private func displayTransactionStatus() { | |
| if let transactionList = getTransactionData()?.data{ | |
| transactionList.forEach({ transaction in | |
| switch transaction.type{ | |
| case .credit: | |
| print("🤑") | |
| case .debit: | |
| print("😓") | |
| case .unknown: | |
| print("🤷🏽♂️") |
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
| class ViewController: UIViewController { | |
| private var transactionData: TransactionData? | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| displayTransactionStatus() | |
| } | |
| private func getTransactionData() -> TransactionData? { |
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
| enum TransactionType: String, Codable{ | |
| case debit | |
| case credit | |
| } | |
| struct TransactionData: Codable { | |
| let data: [Transaction] | |
| } | |
| struct Transaction: Codable { |
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 TransactionData: Codable { | |
| let data: [Transaction] | |
| } | |
| struct Transaction: Codable { | |
| var id: String? | |
| var type: TransactionType? | |
| enum CodingKeys: String, CodingKey { | |
| case id = "_id" |
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
| { | |
| "data": [ | |
| { | |
| "type" : "credit", | |
| "_id" : "123abc" | |
| }, | |
| { | |
| "type" : "debit", | |
| "_id" : "123def" | |
| }, |
NewerOlder