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

Generalized accessors

Generalized accessors

C114c127f13522da92cb03e5d14946ca?s=128

Takuma Shimizu

March 27, 2019
Tweet

Transcript

  1. subscrit get set

  2. 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 { ... } }
  3. 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 } }
  4. Swift 4.2 mutableAddressWithPinnedNativeOwner Swift 5 read , modify yield co-routine

  5. 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 } }
  6. yield subscript(index: Int) -> inout Element {} inout Rust Lifetime

    Rust Swift
  7. yield

  8. !