需要将字符串数组转换为URL数组。在Swift中,需要有人帮我将String数组转换为URL数组。
let urls = ["www.1.com", "www.1.com", "www.1.com", "randomSmth"].compactMap { URL(string: $0) }
"compactMap" 确保它只忽略无效的 url。
let arrayOfStrings = ["https://www.google.com","https://www.facebook.com", "notRerallyAnURL"]
let arrayOfURLs = arrayOfStrings.compactMap { URL(string:$0) }