|
Hello, I wanted a little bit of rest rom the 100 days and I wanted to practice writing my own, AppStore-shippable app. However it seems I am not ready yet lol. Here is my API class:
import Foundation import SwiftUI struct NewsView: View { private let api = TyfloAPI.shared @State private var podcasts = [Podcast]() var body: some View {
}
|
|
In getLatestPodcasts, try putting some print statements to try to debug where things are going wrong... |
|
Replace this code:
with this:
In the first snippet, the use of I would recommend never using (At first glance, I'm betting the problem is that the JSON is returning an array of Also, this:
I would suggest keeping the return value as an empty array. An |
|
I have got an error that the data is in an incorrect format. So I have decide to rewrite my model like so // // Podcast.swift // Tyflocentrum // // Created by Arkadiusz Świętnicki on 24/10/2022. // import Foundation struct PodcastResponse: Codable { var podcasts: [Podcast] } struct Podcast: Codable, Identifiable { struct PodcastTitle: Codable { var rendered: String } var id: Int var date: Date var title: PodcastTitle var excerpt: PodcastTitle } However I still get the same error. You can see my JSON when you go to tyflopodcast.net/wp-json/wp/v2/posts?per_page=100 |
|
When posting code to these forums, place three backticks This makes it far easier to read and also makes it easier for other posters to copy/paste the code in order to test solutions and such. Doing this will ensure that you end up with something like this:
instead of this: // // Podcast.swift // Tyflocentrum // // Created by Arkadiusz Świętnicki on 24/10/2022. // import Foundation struct PodcastResponse: Codable { var podcasts: [Podcast] } struct Podcast: Codable, Identifiable { struct PodcastTitle: Codable { var rendered: String } var id: Int var date: Date var title: PodcastTitle var excerpt: PodcastTitle } However I still get the same error. You can see my JSON when you go to tyflopodcast.net/wp-json/wp/v2/posts?per_page=100 |
|
|
|
Try something like this:
|
|
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.