To be simpler, we obtain the user location at a given moment just once, without the need to keep listening to location changes. As pointed before, we want to simplify and hide the complexity of Apple’s CLLocationManager, that is implemented through the delegation pattern via the CLLocationManagerDelegate protocol. Take for instance our LocationManager class. Being more loosely coupled makes it easy to replace that facaded component in case we want to use a new technology.We make it easier to mock and thus improve testability in our code.We improve the readability and usability of that component with an easier API that hides the details of a more complex one.The purpose of this pattern is manyfold, but three points really stand out for us: In our iOS team, we like to facade some Apple or third party developers components with our own ones. Facading a delegate Based class with Continuations This is helpful when facading third party libraries or Apple APIs containing these patterns, as in the case that we will see today. This might still sound very abstract, but we can learn to appreciate it deeper when considering how Apple implements asynchronous code up until now, with callbacks and the delegate pattern.Ĭontinuations shine with all their brightness when working with these two patterns: they act as a bridge between the old world (callbacks and delegates) and the new one ( async/await to achieve a more readable and structured code) by helping to create new async functions facading the old ones. More precisely, a Continuation is an object that captures the program state at a given point, being able to continue it when it is required. What are Continuations?Īccording to the documentation, Continuations are a mechanism to interface between synchronous and asynchronous code, logging correctness violations. However, there was another mechanism introduced then that didn’t capture so much consideration even though they are very powerful when working together with async/await: Continuations. And rightly so, these new additions improved considerably the readability of asynchronous code and the easiness when ensuring thread safety in our apps. This new architecture fulfilled all the expectations that we iOS developers had, who were eagerly waiting for this since the Swift first release in 2014, and whose hopes got boosted in 2017 with the Swift Concurrency Manifesto by Chris Lattner himself.įrom all the new APIs and tools that were introduced, the new async/await syntax, Actors, and Tasks attracted most of the attention from the Swift community. The new async/await Swift concurrency API released together with Swift 5.5 was finally unveiled during the WWDC 21 last June.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |