The Swift Programming Language (Swift 5.7) - Apps Dissected
key path to access the second element of an array: 1 let greetings = ["hello", "hola", "bonjour", "안녕"] 2 let myGreeting = greetings[keyPath: \[String].[1]] 3 // myGreeting is 'hola' The value used Because 'fn' closes over 'index', it uses the new value 16 print(fn(greetings)) 17 // Prints "안녕" The path can use optional chaining and forced unwrapping. This code uses optional chaining in a0 码力 | 1040 页 | 10.90 MB | 1 年前3
共 1 条
- 1