Need to convert array of string value to array of URL. Some one help me to convert the String array to URL array in swift.
2 Answers
let urls = ["www.1.com", "www.1.com", "www.1.com", "randomSmth"].compactMap { URL(string: $0) }
"compactMap" ensures that it just ignores invalid urls.
1 Comment
10623169
Upvoting your answer because you were the first to provide a valid solution that didn't include force unwrapping (a ton of duplicates just appeared). This should be marked as the correct answer.