Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
568 views
in Technique[技术] by (71.8m points)

How to merge two arrays in Swift

I have two arrays.

let A = ["91","91","49"]
let B = ["9989898909","9089890890","9098979896"]

I need to merge these arrays and show it in the dropdown as

["91 9989898909","91 9089890890","49 9098979896"]

How can I get this result using swift.Im newbie to swift,can anyone please help on this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Zip the arrays and concatenate the results:

let A=["91","91","49"]
let B=["9989898909","9089890890","9098979896"]
let zipped = zip(A, B)
let result = zipped.map { $0.0 + " " + $0.1 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...