Swift 2.0 Programming : Design Patterns : The Singleton Pattern

preview_player
Показать описание
Get Our Auto Layout Course at A Great Discount. Click HERE :

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:
=========

Tools Used:
==========
Microphone : Blue Yeti
Voice Editor : Audacity
Animation : Sparkol Video scribe
Video editor + SFX : iMovie + ScreenFlow
Computer : MacBook Air

Individuals involved in Video:
=================
Sanjay Noronha , Ravi Shankar
Рекомендации по теме
Комментарии
Автор

This was a great tutorial on singletons. Thanks very much!

bmt
Автор

Great Tutorial. I am weak in swift. My demand is I want a full basic video in swift..

rasmiranjansahu
Автор

Excellent tutorial Sanjay. Looking forward to other design pattern tutorials

RaviShankar-vxus
Автор

this is a excellent explanation. thanks for telling such complex thing so easily.

codeelsewhere
Автор

Nicely explained and very helpful thanks. you should do one on closures in swift and all of their uses

msingh
Автор

thank you for this tutorial...

Also, you have an amazing accent!

JamesSmith-opqz
Автор

Tried to use private init(), but no luck. There is no any errors in XCode 7.3.1 playground whle tryinh to instantiate class...

class SingletonePattern {
var prop: Int = 0
private init(){}

class var getInstance: SingletonePattern {
struct Singletone {
private static var instance = SingletonePattern()
}
return Singletone.instance
}

}
var trick = SingletonePattern() //It just works...

fedor_U