Advertisement
Larme

Untitled

Jan 14th, 2021
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.97 KB | None | 0 0
  1. func findingURLs() {
  2.     let initials = ["Call me by your name https://www.amazon.de/dp/B07B58SGWP/ref=cm_sw_r_cp_api_fabc_iCJ6Fb0QVVW8Y?_encoding=UTF8&psc=1",
  3.                     "https://farfetch.onelink.me/yQyB/b9f5e5d2?af_dp=https%3A%2F%2Fwww.farfetch.com%2Fshopping%2Fitem-16119737.aspx&af_web_dp=https%3A%2F%2Fwww.farfetch.com%2Fitem-16119737.aspx Shoppen Golden Goose 'Hi Star' Sneakers",
  4.                     "Schau dir LANDSKRONA von IKEA an. Hier noch weitere Informationen: https://ingka.page.link/gqV9dAw61TqNJrne9",
  5.                     "https://www.amazon.de/DALLE-PIANE-CASHMERE-Anthrazit-Einheitsgröße/dp/B06XY2ZGBZ/ref=mp_s_a_1_13_sspa?dchild=1&keywords=dalle%2Bpiane%2Bcashmere%2Bschal&qid=1610091194&sprefix=dalle%2Bpia&sr=8-13-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUExT0hHOFRLWElYVUJBJmVuY3J5cHRlZElkPUEwOTY1ODUyOUJWWUU4MlY0SVUwJmVuY3J5cHRlZEFkSWQ9QTA0ODk2NzEzSDZNSUJOR1haREVTJndpZGdldE5hbWU9c3BfcGhvbmVfc2VhcmNoX210ZiZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU&th=1",
  6.                     "https://www.apple.com/de/shop/buy-ipad/ipad-air/64gb-grün-wifi"]
  7.  
  8.     initials.forEach { aString in
  9.         let components = aString.components(separatedBy: .whitespacesAndNewlines)
  10.  
  11.         let url: URL? = components.compactMap {
  12.             if $0.hasPrefix("http") {
  13.                 if let asSuch = URL(string: $0) {
  14. //                    print("As such")
  15.                     return asSuch
  16.                 } else {
  17.                     if let percentEscaped = $0.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
  18. //                        print("Percent Escaped")
  19.                         return URL(string: percentEscaped)
  20.                     } else {
  21. //                        print("Couldn't percent escape")
  22.                         return nil
  23.                     }
  24.                 }
  25.             } else {
  26.                 return nil
  27.             }
  28.         }.first
  29.         print("In \(aString)\n found: \(url?.absoluteString)")
  30.     }
  31. }
  32.  
  33. findingURLs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement