Posts

Post not yet marked as solved
7 Replies
1.8k Views
Apple developed Project files from Intro to App Development Lesson 16 on QuestionBot 2 are giving me errors as follows:The project will build and run fine. It will also answer the first question. However, asking a 2nd question causes an error of "Thread 1: signal SIGABRT". This is a file straight from the Apple Tutorial. Suggestions?Project files give warnings for depricated code are given as follows: "The use of Swift 3 @objc inference in Swift 4 mode is deprecated." Suggestions?Thanks,Mike
Posted Last updated
.
Post not yet marked as solved
0 Replies
135 Views
Apple's online "Books" for App Development have been updated, and yet the most recent Develop In Swift Fundamentals from July, 2020 seems to be using UIKit and Storyboard rather than SwiftUI. Have I missed something? Is there another Apple Book to teach young programmers that includes SwiftUI? Thanks, Mike
Posted Last updated
.
Post marked as solved
4 Replies
910 Views
We are new programmers and are trying to parse an Exchange Rate API. We are able to pull data from the API, but are unable to extract and use that data.Line 54 shows the API is working, and will show the correct data in the debug area.Line 58 is, we believe, the problem area.Any suggestions are appreciated.Kind Regards,import UIKit struct ExchangeRates: Decodable { var base: String = "" var rates: [String: Double] } class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. getExRate(currencyBase: "USD") //this whole for-in loop did not work for (key, value) in updatedExRates { // var exchangeRateValue: Double if (key == "HUF"){ // exchangeRateValue = value print(value) displayLabel.text! = "\(key): \(value)" } } } @IBOutlet weak var displayLabel: UILabel! var updatedExRates = [String: Double]() func getExRate(currencyBase: String) { // ((completion: @escaping(Result<exchangerates, currencyerror="">) -> Void)) let resourceString = "https://api.exchangeratesapi.io/latest?base=\(currencyBase)" let resourceURL = URL(string: resourceString) print(resourceURL!) guard resourceURL != nil else{ return } let session = URLSession.shared let dataTask = session.dataTask(with: resourceURL!) { (data, response, error) in //check for error if error == nil && data != nil { //parse JSON let decoder = JSONDecoder() do{ let exRates = try decoder.decode(ExchangeRates.self, from: data!) print(exRates) //this works(see debug area) // this is where the issue started to occur. //It does not assign the dictionary to this variable I have created(returns nil instead). self.updatedExRates = exRates.rates } catch { print("error in JSON parsing") } } } //Make the API call dataTask.resume() } }
Posted Last updated
.