-1

I'm trying to create an URLComponents object so I can extract parameters values from a string. I have the string topic_id12&lessong_id=45:

let dataString = "topic_id12&lessong_id=45"
guard let urlComponents = URLComponents(string: "https://somedomain.com/\(dataString)/") else return { nil }

However the init fails. Any ideas what I'm missing here? Thanks

Kex
  • 8,023
  • 9
  • 56
  • 129
  • I don't know what you mean by fail (it does not return nil). What is the expected result for your URL ? the example above would result in [https://somedomain.com/topic_id12&lessong_id=45/](https://somedomain.com/topic_id12&lessong_id=45/) – Leo Dabus Dec 27 '20 at 13:23

1 Answers1

-2

You can safely remove guard and else return { nil } part from your code.

iamimran
  • 110
  • 2
  • 7