I am getting this error:
“The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions”
asking me to breakup my expression because it is too long. How should this be broken up but still be able to feed into one UILable?
businessAddress.text = street + " " + "Unit " + unit + " " + "\n" + city + ", " + state + " " + postalCode
class OfferViewController: UIViewController {
var quote: Quote?
var unit: String!
var street: String!
var city: String!
var state: String!
var postalCode: String!
// var numbersOfOrders: String!
// var totalMilage: String!
// var payment: String!
// @IBOutlet var orderMilage: UILabel!
@IBOutlet var businessAddress: UILabel!
@IBOutlet var businessName: UILabel!
// @IBOutlet var paymentOffer: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
//fetchLocalData()
fetchRemoteData()
}
func fetchLocalData() {
let jsonUrl = Bundle.main.url(forResource: "quote", withExtension: "json")
do {
// Read the file into a data object
let jsonData = try Data(contentsOf: jsonUrl!)
let decoder = JSONDecoder()
do {
let decodedData = try decoder.decode(Quote.self, from: jsonData)
quote = decodedData
} catch {
print("Unable to decode JSON data \(error.localizedDescription)")
}
} catch {
print("Unable to find JSON data")
}
}
func fetchRemoteData() {
let urlString = "https://www.goedash.com/_functions/quoteapi/quote"
let url = URL(string: urlString)
let defaultSession = URLSession(configuration: .default)
let dataTask = defaultSession.dataTask(with: url!) { data, response, error in
if error != nil {
print(error!)
return
}
do {
let json = try JSONDecoder().decode(Quote.self, from: data!)
print(defaultSession)
DispatchQueue.main.async { [self] in
self.quote = json
self.businessName.text = self.quote?.brandName.codingKey.stringValue
unit = self.quote?.pickup.unit.codingKey.stringValue
street = self.quote?.pickup.street.codingKey.stringValue
city = self.quote?.pickup.city.codingKey.stringValue
state = self.quote?.pickup.state.codingKey.stringValue
postalCode = self.quote?.pickup.postalCode.codingKey.stringValue
businessAddress.text = street + " " + "Unit " + unit + " " + "\n" + city + ", " + state + " " + postalCode
}
} catch {
print(error)
}
}
dataTask.resume()
}
}