martinko2499 martinko2499 - 1 year ago 140
iOS Question

Why Does Swift print "Optional(455 bytes)"

I am working on a weather app, and trying to get the data from an API. But when I type in a city name and hit enter, Swift prints out a message "Optional(455 bytes)" Not sure what goes wrong.

import Foundation

protocol WeatherServiceDelegate{
func setWeather(weather:Weather)

class WeatherService{
var delegate: WeatherServiceDelegate?

func getWeather(city: String){
let path = ""
let url = URL(string: path)

let task = URLSession.shared.dataTask(with: url!) { (data:Data?, response: URLResponse?, error: Error?) in


Answer Source

There's nothing wrong, what you are trying to do is, print an iOS encoded Data from a optional variable data of type Data?

You should rather be checking the response after decoding it.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download