Networking with URLSession · Session Tasks | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/7476-networking-with-urlsession/lessons/6

Hi! Why do you use NSString(data…) as String instead of just using String(bytes: encoding:) to make string from data?

Thanx

Good point - thanks for the heads up.

On: configuration.waitsForConnectivity = “true”
I get this error: Expressions are not allowed at the top level

I have Swiftt & Xcode 10.2.1

That’s hard to diagnose what’s occurring here. Would you please provide more code?

Ah Sorry. I see you were using playground just for basic demo of components. It was just that playgrounds was acting funny as usual so I tried to go to project with your playground code

Put in playground and works. (now)

1 Like

@ingo69 Glad you sorted it out! Cheers! :]

Error Domain=NSURLErrorDomain Code=-1202
“The certificate for this server is invalid. You might be connecting to a server that is pretending to be “jsonplaceholder.typicode.com” which could put your confidential information at risk.”

got the above error with https, How can i resolve it? But it works with http

Yeah, their certificate doesn’t appear valid anymore. This looks to be ATS preventing the connection. You could put an exception for the site in your info.plist. You can check out the episode on Application Transport Security to learn how to do this.

Cheers!