EXTRACTION METHOD OF MULTIPLE INDEX OF NUMBER 1 FROM TAPPLE

Asked 2 years ago, Updated 2 years ago, 73 views

// Array contains tuples.(String, Int)
Is it possible to extract only the number 1 index from this array?
let aaa=[("a", 1210),("i", 1215),("u", 1220),("i", 1228),("a", 1230)]

// I want to create an array like this
let bbb=[1210, 1215, 1220, 1228, 1230]

Please

swift2

2022-09-30 10:22

1 Answers

map is valid if you want to retrieve the result of applying the same operation to all elements of an array as a new array.

let aaa=[("a", 1210),("i", 1215),("u", 1220),("i", 1228),("a", 1230)]
let bbb=aaa.map {$0.1}//->[1210, 1215, 12220, 1228, 1230]

This feature exists from Swift 1.0 (and earlier beta versions).Unless it's specific to Swift 2.x, many of you may want to tag language questions without version numbers.


2022-09-30 10:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.