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

Generalized accessors

Generalized accessors

Takuma Shimizu

March 27, 2019
Tweet

More Decks by Takuma Shimizu

Other Decks in Programming

Transcript

  1. get let nums = Array(0..<10) let x10 = nums[3] *

    10 // `get` print(num) subscript(index: Int) -> Element { get { let element = // `index` return element // } set { ... } }
  2. set var nums = Array(0..<10) let num = nums[3] nums[3]

    = num * 10 // `set` print(num) subscript(index: Int) -> Element { get { ... } set(newValue) { // `newValue` // buffer = newValue } }
  3. read // CoreAudio.swift subscript(index: Index) -> Element { _read {

    yield ((_audioBuffersPointer + index).pointee) } } modify // Array.swift subscript(index: Int) -> Element { _modify { let address = _buffer.subscriptBaseAddress + index yield &address.pointee } }
  4. !