Swift 2.0 Programming : Design Patterns : The Singleton Pattern

Опубликовано: 02 Ноябрь 2024
на канале: funza Academy
9,320
130

Get Our Auto Layout Course at A Great Discount. Click HERE :
http://rshankar.com/courses/autolayou...

Link to code : https://github.com/funzaAcademy/Singl...

Swift 2.0 Programming : Design Patterns : The Singleton Pattern
In this video we will see a simple example of the Singleton pattern in Swift.

Overview:
=========
As you gradually get familiar with the Swift landscape, one thing will be pretty Obvious : The presence of design patterns.
You will start noticing patterns such as Observers, Singletons, Factories and many more.
So why are design patterns important ?
Well for one thing, experienced designers do not solve problems from scratch or first principles.
Rather, they use solutions that have worked in the past.
Design patterns capture these workable solutions.
To take another example, image yourself as a movie director. When you think of a theme you think patterns: Super hero, Tragically flawed Hero Etc.
Once you know the pattern, design decisions automatically follow.
In this video we will look at the Singleton design pattern.
Lets start with definitions.
Ok, so why does this pattern exist ?
Well, the Singleton pattern is a Creational Pattern. It affects the process of Object Creation.
Great.. And ?
And it ensures that a class has only 1 Object instance.
Now thats interesting. Typically a class has many instances or Objects. But ONE? Why would we want one?
Well, take the UIApplication class in Swift.
Every app has exactly 1 instance of this class. And this instances handles the Apps user events among other things.
It does not make sense for your app to have more than 1 instance.

In this video we will see a simple example of the Singleton pattern in Sw


References:
=========
http://rshankar.com/
http://krakendev.io/blog/the-right-wa...
http://stackoverflow.com/questions/29...
http://stackoverflow.com/questions/29...
https://www.makeschool.com/tutorials/...
http://stackoverflow.com/questions/24...
https://developer.apple.com/library/i...
http://koreyhinton.com/blog/singleton...
https://developer.apple.com/swift/blo...
https://www.makeschool.com/tutorials/...
Gang of 4 design pattern book : https://en.wikipedia.org/wiki/Design_...


Tools Used:
==========
Microphone : Blue Yeti
Voice Editor : Audacity
Animation : Sparkol Video scribe
Illustrations: funza Academy + openclipart.org
Video editor + SFX : iMovie + ScreenFlow
Computer : MacBook Air


Individuals involved in Video:
=================
Sanjay Noronha , Ravi Shankar