Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Weak, Strong, Unowned - Hector Matos
Search
Realm
August 03, 2015
0
49k
Weak, Strong, Unowned - Hector Matos
Realm
August 03, 2015
Tweet
Share
More Decks by Realm
See All by Realm
WWDC 2017 Review
realm
0
2.1k
Xcode shortcuts
realm
0
4.7k
Self Branding with GitHub
realm
0
4.3k
Realm Mobile Platform overview and demo
realm
0
2k
Realm advanced topics and demo
realm
0
2k
Realm introduction Seoul meetup 10
realm
0
2.1k
Stuart Hall: How I got 2.3 Million App Downloads
realm
0
1.9k
James Majors: What the Swiftly Func?
realm
1
4.3k
Simina Pasat: Continuous everything for iOS apps
realm
0
620
Featured
See All Featured
The Invisible Side of Design
smashingmag
301
51k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
The Cult of Friendly URLs
andyhume
79
6.5k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.3k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Code Reviewing Like a Champion
maltzj
524
40k
Transcript
Weak, Strong, Unowned Oh, My!
Quick Intro
Hi! I'm Hector Matos
None
Sr. Software Engineer @ Capital One
@allonsykraken on the Twitters
Father of KrakenDev.io
ARC
- (void)releaseTheKraken { Kraken *kraken = [[Kraken alloc] init]; //+1
retain [kraken release]; //generated by ARC }
Magic has it's limitations And so does ARC
Leaked Memory & Retain Cycles
None
None
Strong References Default in Swift
Now Stop, Example Time //Kraken holds a strong reference to
the yummy human. class Kraken { var yummyHuman: Human }
// The animation closure holds a strong reference to self
// self.retainCount is 1 here UIView.animateWithDuration(0.3) { // self.retainCount is 2 here self.view.alpha = 0.0 }
Questions?
Weak References Safe - Independent
Stop, Collaborate, & Listen! (to my next example) class KrakensFace:
UIView { @IBOutlet weak var razorSharpTeeth: UIView! } KrakenAPI.eat(yummyHuman, whenFinished: { [weak self] in self?.waitForNextMealTime() })
WTF is "[weak self] in"?!
Capture Lists It's just an array. That's all it is.
There, there. It's all over now. !
KrakenAPI.eat(yummyHuman, finished: { [weak self, unowned lovedOne = yummyHuman.lovedOne] in
self?.waitForNextMealTime() })
Questions?
Unowned References Mutual Dependence
class Human { var heart: ! func seeKrakenComing() { heart.haveHeartAttack()
} } class !: Organ { unowned let human: Human init(human: Human) { self.human = human } func haveHeartAttack() { human.die() } } let human = Human() human.heart = !(human: human)
Questions?
None
❤