HTTP Request in swift not working

后端 未结 6 956
攒了一身酷
攒了一身酷 2021-02-03 10:19

I\'m trying to learn about working with APIs in Swift. As a good first test, I figured I\'d hit the itunes API and just return some search results. I\'m in playground using the

6条回答
  •  北海茫月
    2021-02-03 11:08

    My answer is not correct, it's really only the in the playgound indefinitite page execution. The session type does not matter.

    Run into the same issue recently and found a solution.

    The error is caused by using URLSession.shared() which apparently is not allowed in a playground sandbox.

    Create and use your own ephemeral URL session instead:

    let session = URLSession(configuration: URLSessionConfiguration.ephemeral)

提交回复
热议问题