Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
Generalized accessors
Takuma Shimizu
March 27, 2019
Programming
0
9
Generalized accessors
Takuma Shimizu
March 27, 2019
Tweet
Share
More Decks by Takuma Shimizu
See All by Takuma Shimizu
hokuron
0
180
hokuron
0
170
hokuron
0
300
hokuron
0
48
hokuron
1
370
hokuron
0
13
hokuron
0
18
hokuron
0
36
hokuron
0
20
Other Decks in Programming
See All in Programming
xrdnk
0
130
s_uryu
0
200
line_developers_tw
0
550
trajchevska
2
380
junmikai
0
300
steipete
PRO
2
160
yagitatsu
3
1.6k
canon1ky
3
350
line_developers_tw2
0
760
e10dokup
0
450
kenmaz
1
100
dulltz
0
520
Featured
See All Featured
brad_frost
156
6.4k
matthewcrist
73
7.5k
addyosmani
1348
190k
michaelherold
225
8.5k
caitiem20
308
17k
bermonpainter
342
26k
jrom
114
7.1k
jakevdp
775
200k
skipperchong
7
670
pedronauck
652
110k
sugarenia
233
840k
destraynor
146
19k
Transcript
subscrit get set
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 { ... } }
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 } }
Swift 4.2 mutableAddressWithPinnedNativeOwner Swift 5 read , modify yield co-routine
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 } }
yield subscript(index: Int) -> inout Element {} inout Rust Lifetime
Rust Swift
yield
!