I was looking for a video not only describing but showing the pitfalls of singletons with unit testing and yours was about as close as I could get to an actual walkthrough. Great content, great advice, great inspiration.
@EssentialDeveloper4 жыл бұрын
Glad it was helpful!
@tityseptiani85846 жыл бұрын
Wow, thank you very much for the explanations! I was excited when you said you'd create a video about singleton. I had to replay the video twice to really get everything you're talking about. I think I'm currently on the Step 3 for my own API client. And it's true that looking at diagrams always scare me because most of the time I don't know how to read them and understand them. Nowadays, I've been trying to get use to creating diagrams whenever I want to do something, to get the better picture of the whole thing. I'll try to implement the step 4 and see how it works. Anyway, I'm still waiting for your premium courses :D Thank you very much Caio and Mike!
@gordonsmith63266 жыл бұрын
Such awesome content again, incredibly refreshing to stumble across a channel like yours. Thank you for breaking this down 👌🏽
@waheedafolabi69293 жыл бұрын
Wow...thanks Mike and Caio for this great content!
@bibinjacob1236 жыл бұрын
Hey,,I like your style. Could you help developers build a singleton networking layer that can be used in all of their projects.
@incelemeTRe2 жыл бұрын
This session was awesome. Thank you very much.
@EssentialDeveloper2 жыл бұрын
Glad you enjoyed it!
@kanishkaralasi74083 жыл бұрын
OMGG! THIS IS EXACTLY WHAT I NEEDED! SO THOUGHTFUL AMD DETAILED 🙌🏼 💯
@IngviMcFly4 жыл бұрын
That the main topic I've been facing for many years when work with legacy code projects. Guys, Thanks for additional information on this topic.
@EssentialDeveloper4 жыл бұрын
Glad it was helpful!
@jeraldo45714 жыл бұрын
Great video. Focusing from start to a path that leads to a good solution. One thing Im trying to understand about modularization, what if the models are shared between different modules? And modules are maintained in different projects? Like an authorization framework should return a loggedInUser that is also used in another module?
@EssentialDeveloper4 жыл бұрын
Hi Jeraldo, you can create a shared module to hold those shared models. But beware that the more clients depend on a module, the harder it can be to change it without breaking clients and redeploy it to all clients. When needed, a solution is to create domain-specific models and DTOs to transfer them without coupling those modules. ✅
@glebcherkashyn23576 жыл бұрын
Another super useful lesson! Once again I see some evident improvements in my projects. Looks like now I understand last of SOLID principles :D Still, at level 4 you can not just take module and use it in another project. You'll have to write adapter, and I'm not sure that it can save too much time... And you have to be sure, that another project has generic ApiClient, otherwise you can't write the adapter =). But if you want replace module to YOUR project, 99% that ApiClient is same there, and the only thing you need is to define new requests, and in this look like you don't need adapter. Am I wrong? In my practice I use generic ApiClient based on Alamofire and Endpoint protocol (provides path, headers, attributes etc.), and generic mapper based on Decodable. So when I need to get something I just say 'hey, give me result with endpoint converted to some type" where endpoint is enum instance that conform 'Endpoint' protocol, and I provide type of model object that conforms Decodable. I wonder which level I'm on now =)
@EssentialDeveloper6 жыл бұрын
Hi Gleb! In our example, the extensions *are* the adapters! In Swift, we can have cross-module extensions which facilitate this approach. Your solution sounds similar to this. As long as the dependencies are clear and pointing in the right direction, your code can be simple and composable. ✅⛩
@chaitanyadeshpande60603 жыл бұрын
Dammmm this was so well explained 👏
@VirenderDall2 жыл бұрын
Hi Caio, Do we need to use weak here or it's not required? class AppCache { static var shared = AppCache() private let queue = DispatchQueue(label: "com.demo", attributes: .concurrent) private var sessionData: [String : String] = [:] func setSessionData(key: String, value: String) { queue.async(flags: .barrier) {[weak self] in self?.sessionData[key] = value } } }
@EssentialDeveloper2 жыл бұрын
Hi Virender! The queue will eventually release the closure after the async call is done (it doesn't retain the closure after the async operation returns). So weak is not needed in this case to prevent retain-cycles because there won't be a memory leak if it's a strong reference. You only need to make it weak if you want to prevent holding the instance for longer than needed (in case the cache can be deallocated while async operations are scheduled) ✅
@david-tracy6 жыл бұрын
So using final allows you subclass or does it allow you to create extensions?
@EssentialDeveloper6 жыл бұрын
Hey, you cannot subclass a "final class." But you can create extensions on any class (even if it's final!). ✅⛩ For more info: docs.swift.org/swift-book/LanguageGuide/Inheritance.html
@abhishekbedi14326 жыл бұрын
Hey Ciao . Can u share the gist on github
@EssentialDeveloper6 жыл бұрын
Hey, here it is gist.github.com/caiozullo/547ed5483221e6cb9509e4134cb1ce09 ✅⛩
@theprimalstocks3 жыл бұрын
There is no swizzing in swift?
@EssentialDeveloper3 жыл бұрын
Swizzling only works for obj-c methods because it requires the obj-c runtime. So you'd need to mark the methods as @objc. Latest Swift versions allow dynamic replacement, but it's more limited.
@VirenderDall2 жыл бұрын
abstract public class Printer { abstract void print(); } public class HPPrinter extends Printer { private static HPPrinter instance; private HPPrinter() { // private constructor } synchronized public static HPPrinter getInstance() { if (instance == null) { instance = new HPPrinter(); } return instance; } @Override void print() { } } Is this we consider Singleton or singleton or some other type of $ingleton
@EssentialDeveloper2 жыл бұрын
Hi Virender, that's a Singleton because it enforces only a single instance (static lazy instance with a private initializer). In Swift: ``` class HPPrinter { static let instance = HPPrinter() private init() {} } ``` *static let is lazy and synchronized by default in Swift
@VirenderDall2 жыл бұрын
@@EssentialDeveloper and we can easily use this in testing
@EssentialDeveloper2 жыл бұрын
Ideally, you shouldn't access the Singletons directly in your components. Otherwise, you can't replace them while testing.
@pankajjha90524 жыл бұрын
In MockAPIClient class I am getting"super.init isn't called" and I think its a valid error ,why it is not there in your case here , am I missing something here?
@EssentialDeveloper4 жыл бұрын
Hello! You do need to call `super.init`. Xcode didn't show the error in the video until we built the project.
@pankajjha90524 жыл бұрын
@@EssentialDeveloper Thanks for clarifying
@hithakshikulal23202 жыл бұрын
@@EssentialDeveloper Calling `super.init` will throw an error "'APIClient' initialiser is inaccessible due to 'private' protection level". Does it mean there is no difference in using static var instead of static let ? In this case, do we have to remove private access from initialiser to make it testable?
@EssentialDeveloper2 жыл бұрын
Hi Hithakshi. In this case, the initializer cannot be private. That's the "lowercase" singleton version (there's a singleton shared instance, but you're still able to create new instances - like URLSession does, for example).
@hithakshikulal23202 жыл бұрын
@@EssentialDeveloper Okay. Got it. Thank you 😊
@PS-dp8yg6 жыл бұрын
Love your videos, but where to start for beginners? Are you planning to do beginners videos?
@EssentialDeveloper6 жыл бұрын
Hi! It depends on your level. If you're a beginner but familiar with the basics of programming already, we recommend to you our course "Swift Feed App Case Study" - academy.essentialdeveloper.com . We're covering advanced topics but with an approachable methodology. It's been popular among beginners as well. We believe you'll greatly benefit from it as others have so far. ✅⛩