I'm starting to work on iOS. I searched the web and could not find an answer that would solve my problem. Stuck and has no idea what to do and how to look for a solution.
I follow the guide based on Swift 2. The following method shows an error.
func downloadBooks(bookTitle: String) { let stringURL = "GET https://www.googleapis.com/books/v1/volumes?q=\(bookTitle)" guard let URL = URL(string: stringURL) else { print("url problems") return } let urlRequest = NSMutableURLRequest(url: URL) let session = URLSession.shared let task = session.dataTask(with: urlRequest) { (data: Data?, response: URLResponse?, error: Error?) in } task.resume() }
I made all the settings suggested by Xcode, but no additional tips.
In addition, the source code from the tutorial was as follows:
guard let URL = NSURL(string: stringURL) else { print("url problems") return }
Xcode then suggested adding as URL , as shown below:
let urlRequest = NSMutableURLRequest(url: URL as URL)
In both versions it is displayed without errors . So what is the difference? Which one should I use?
I am very grateful for any help!
Marat source share