Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Weak, Strong, Unowned - Hector Matos

Realm
August 03, 2015
49k

Weak, Strong, Unowned - Hector Matos

Realm

August 03, 2015
Tweet

Transcript

  1. ARC

  2. - (void)releaseTheKraken { Kraken *kraken = [[Kraken alloc] init]; //+1

    retain [kraken release]; //generated by ARC }
  3. Now Stop, Example Time //Kraken holds a strong reference to

    the yummy human. class Kraken { var yummyHuman: Human }
  4. // 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 }
  5. Stop, Collaborate, & Listen! (to my next example) class KrakensFace:

    UIView { @IBOutlet weak var razorSharpTeeth: UIView! } KrakenAPI.eat(yummyHuman, whenFinished: { [weak self] in self?.waitForNextMealTime() })
  6. Capture Lists It's just an array. That's all it is.

    There, there. It's all over now. !
  7. 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)