The wikipedia definition of a software design pattern is
A reusable solution to a commonly occuring problem in the context of software design.
Gang of four book in 1994 formalised a number of design patterns. Here we are going to talk more specifically about the common design patterns when it comes to iOS app development.
This is different from the architectural design patterns, MVC or MVVM or Viber or clean architecture.
Structural design patterns are more about managing the piece of codes in reusable way.
When someone says something is dynamic, it usually means things could change. Dynamic array, meaning the content of the array could change, or a dynamic system could mean a system that is robust and can adapt to different input scenario.
So, what does it mean for a framework to be a dynamic framework, or static framework? Or when someone says Python is a dynamically typed language but Swift is a statically typed language?
Deadlock is a situation when two or more threads are waiting on each other to be completed causing both to be locked and not able to continue.
A practical example of a deadlock is
Let’s see an example in swift.
here, the the queue is exeucting with q.async first, inside the block it calls for q.sync. So the outer block can only complete when the inner block q.sync is finished, but q.sync cannot start, because it is a sync block unless the thread is free. This results in a deadlock and the process will crash.
Race condition happens when 2 or more threads access the shared data at the same time and change its value at the same time resulting in unexpected state.
A simple example is the typical ATM withdraw problem.
ATM withdraw problem
Let’s say we have our own bank account system and we have ATMs depoloyed all over the town to make withdrawl easy.
It’s been a while I’ve updated my posts. Here are some new tips that makes coding with swift cool.
@autoclosure
@autoclosure attribute defines an argument that automatically gets wrapped in a closure. It’s used to defer the execution of an expression to the site of use, rather than when the argument is passed.