Skip to content

Instantly share code, notes, and snippets.

@emaloney
emaloney / guard-closure.md
Last active August 1, 2023 00:24
A simplified notation for avoiding the weak/strong dance with closure capture lists

Simplified notation for avoiding the [weak self]/strongSelf dance with closures

  • Proposal: TBD
  • Author: Evan Maloney
  • Status: Draft
  • Review manager: TBD

Introduction

Frequently, closures are used as completion callbacks for asynchronous operations, such as when dealing with network requests. It is quite common to model these sorts of operations in such a way that an object instance represents a request/response transaction, for example:

@emaloney
emaloney / upgrade-weak-self.md
Last active March 9, 2018 20:12
Allow using optional binding to upgrade a weakly-captured self to a strong reference

Allow using optional binding to upgrade self from a weak to strong reference

  • Proposal: TBD
  • Author: Evan Maloney
  • Status: Draft
  • Review manager: TBD

Introduction

When working with escaping Swift closures, it is a common pattern to have the closure capture self weakly to avoid creating an object reference cycle.

@emaloney
emaloney / abstract-classes.md
Created February 24, 2016 22:30
Allow declaration of abstract functions and properties on Swift classes

Allow declaration of abstract functions and properties on classes

  • Proposal: SE-NNNN
  • Author: Evan Maloney
  • Status: Draft
  • Review manager: TBD

Introduction

Swift protocols are useful for the declaring interfaces that must be provided by conforming entities (in other words: structs, classes and enums). Adopters of a given protocol are free to provide any implementation they wish, so long as it supplies the necessary interfaces.