Avatar
Q2 override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) // User の JSON の取得 Task { do { let url: URL = .init(string: "https://koherent.org/fake-service/api/user?id=\(id)")! let userData: Data = try await downloadData(from: url) let user: User = try JSONDecoder().decode(User.self, from: userData) // View への反映 title = user.name nameLabel.text = user.name // アイコン画像の取得 let iconData: Data = try await downloadData(from: user.iconURL) // Data を UIImage に変換 guard let iconImage: UIImage = .init(data: iconData) else { // エラーハンドリング print("The icon image at \(user.iconURL) has an illegal format.") return } // View への反映 iconImageView.image = iconImage } catch { // エラーハンドリング print(error) } } }