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 UIKit | |
| let appDelegateClass: AnyClass = NSClassFromString("TestingAppDelegate") ?? AppDelegate.self | |
| UIApplicationMain(CommandLine.argc, | |
| CommandLine.unsafeArgv, | |
| nil, NSStringFromClass(appDelegateClass)) |
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 UIKit | |
| class AppDelegate: UIResponder, UIApplicationDelegate { | |
| var window: UIWindow? | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
| print("--> Launching from \(type(of: self))") | |
| window = UIWindow(frame: UIScreen.main.bounds) |
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 UIKit | |
| @objc(TesingAppDelegate) | |
| class TestingAppDelegate: UIResponder, UIApplicationDelegate { | |
| var window: UIWindow? | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
| print("--> Launching from \(type(of: self))") | |
| window = UIWindow(frame: UIScreen.main.bounds) |
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 UIKit | |
| @main | |
| class AppDelegate: UIResponder, UIApplicationDelegate { | |
| var window: UIWindow? | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
| print("--> Launching from \(type(of: self))") | |
| window = UIWindow(frame: UIScreen.main.bounds) |
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
| // Without Dependency Injection | |
| class Company { | |
| var name: String | |
| // `ceo` is dependency here, but Company initializes the ceo object, | |
| // `Company` knows how to initilize the ceo | |
| var ceo: Employee = Employee(name: "Steve", salary: 12344) | |
| init(name: String) { | |
| self.name = name | |
| } |
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: Protocol | |
| /* | |
| protocol is a set of rules, whichever class adopts the protocol, needs to implement the variables and functions declared inside that protocol. | |
| For the below protocol Car, it has two requirements, model and topSpeed. | |
| So if any class or struct adopts this protocol, needs to implement model and topSpeed. | |
| */ | |
| protocol Car { |
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 AEMValue { } | |
| extension String: AEMValue { } | |
| extension Int: AEMValue { } | |
| struct AEMDictionary<T> { | |
| private let container: [String: T] | |
| init(_ dict: [String: T]) { | |
| container = dict |
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
| //MARK: Custom Implmentation of map, filter, reduce, flatMap | |
| public extension Array { | |
| //map | |
| func map2<T>(_ transform: (Element) -> T) -> [T] { | |
| var mapped = [T]() | |
| mapped.reserveCapacity(count) | |
| for element in self { | |
| mapped.append(transform(element)) | |
| } | |
| return mapped |
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 Employee { | |
| let name: String | |
| private var _employer: Company | |
| var employer: Company { | |
| mutating get { | |
| if !isKnownUniquelyReferenced(&_employer) { | |
| _employer = _employer.copy() as! Company | |
| } | |
| return _employer |
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 Company: NSCopying { | |
| var name: String = "Confidential" | |
| func copy(with zone: NSZone? = nil) -> Any { | |
| let copy = Company() | |
| copy.name = name | |
| return copy | |
| } | |
| deinit { |
NewerOlder