Making an API call and fetch JSON data in SwiftUI

Поділитися
Вставка
  • Опубліковано 30 вер 2024
  • Pulling data from an API is an extremely useful technique in SwiftUI. Full 40-video course: designcode.io/s...

КОМЕНТАРІ • 85

  • @glkrishnakumar
    @glkrishnakumar 3 роки тому +3

    My app is crashing even after copying exactly the same code. Don't know where the error is

    • @longlong6040
      @longlong6040 3 роки тому

      I just tried without any compile or runtime issue.

  • @Hendrik6
    @Hendrik6 3 роки тому +3

    Thanks for sharing! Awesome tutorial. I used that with the OpenWeatherMap API and had to remove the [ ] brackets at let posts = try! JSONDecoder().decode([POST].self, from: data!) --> let weatherData = try! JSONDecoder().decode(WeatherData.self, from: data!). With the [ ] brackets, I got an error describing that the decoder wanted to decode an array but received a dictionary. Without the [ ] brackets, my code is running.

  • @jeeves251
    @jeeves251 4 роки тому +27

    OMG THANK YOU. Best tutorial ever. Was struggling all day to get my api to return data to a List. You are a brilliant teacher and I love the way you make your code simple enough for a SwiftUI newbie to understand! Thank you a million times!

    • @DesignCodeTeam
      @DesignCodeTeam  4 роки тому +3

      jeeves251 thank you, that means a lot!

    • @raidenfranco3769
      @raidenfranco3769 3 роки тому

      Sorry to be offtopic but does anyone know of a tool to get back into an Instagram account??
      I stupidly forgot my account password. I love any assistance you can give me.

    • @rydernikolas8860
      @rydernikolas8860 3 роки тому

      @Raiden Franco Instablaster :)

    • @raidenfranco3769
      @raidenfranco3769 3 роки тому

      @Ryder Nikolas I really appreciate your reply. I got to the site thru google and im trying it out now.
      Takes a while so I will get back to you later with my results.

    • @raidenfranco3769
      @raidenfranco3769 3 роки тому

      @Ryder Nikolas it did the trick and I now got access to my account again. I'm so happy:D
      Thanks so much you saved my account!

  • @yeserguitar
    @yeserguitar 3 роки тому +6

    Best tutorial! You literally explained everything one needs in 15 minutes, which could be understood after hours of fail!

  • @olegtitov1525
    @olegtitov1525 4 роки тому +6

    Hey Meng, really nice tutorial. I’m learning SwiftUI, built an app with static cards and now will use this knowledge in practice and make cards load from API. Thanks a lot for your videos!

  • @JIPPOKIKKA
    @JIPPOKIKKA 3 роки тому +1

    I got crash every time. Why?

  • @danielwatson6529
    @danielwatson6529 3 роки тому +1

    i had to change my id from =UUID() to an int to stop errors

  • @VinceVideoHD1k995
    @VinceVideoHD1k995 3 роки тому +2

    So clear and concise. I have watched so many of videos on this topic and by far yours is the best!

  • @rafaafeitos
    @rafaafeitos 3 роки тому +1

    Awesome, I was trying to do it for hours. Thank you very much for this brilliant video!
    Liking, subscribing, learning

  • @bbulliard
    @bbulliard 2 роки тому +1

    This is the best Jason explanation on the internet. Thank you for a world class video…bob

  • @raquelaranda6687
    @raquelaranda6687 4 роки тому +1

    Muchas gracias por tus vídeos. Estoy aprendiendo por puro placer. Me he atrancado en los últimos segundos. List (0..

  • @serdaronurkaradag7666
    @serdaronurkaradag7666 Рік тому

    Hey, i want to add new items to api. I can do that with offline storage but what about online ? I can use firebase but i want to make my own database, fetch api and add new ones. Any suggestions ?

  • @robertricker4908
    @robertricker4908 4 роки тому +2

    Dear DesignCode! I really like the music that plays on the background of your videos! Always wanted to ask, who is the composer?

  • @valonhyseni9826
    @valonhyseni9826 2 роки тому

    Hello, in my case i need the list of posts in 5 different view, how do i store the data i got from the url in a list which i can use in several views. Or should i just save it every time i get it with onappear. Please help

  • @wensmusic8636
    @wensmusic8636 2 роки тому

    Do you have a similar video like this using UIKit ?

  • @cameraGHOST
    @cameraGHOST Рік тому

    Bro you are incredible. TYSM

  • @a3igner
    @a3igner 3 роки тому

    I am using exactly your code and getting this error:
    2021-01-17 16:52:13.697259+0100 XYZ[14020:4668295] Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "id", intValue: nil)], debugDescription: "Expected to decode String but found a number instead.", underlyingError: nil)): file XYZ/ContentView.swift, line 24
    What is the problem?

  • @aungphyoe173
    @aungphyoe173 4 роки тому +1

    Thanks...that's a lot clear to me on SwiftUI and APIs session

  • @DavideBelardi
    @DavideBelardi 2 роки тому +1

    Can I use the same structure that you've made it for APIs like The movie db?

    • @DesignCodeTeam
      @DesignCodeTeam  2 роки тому

      Yes probably as long as it's using a REST API with JSON data.

  • @mrglwatson
    @mrglwatson 4 роки тому +1

    Great video, how do I get the next part?

  • @purpuro8178
    @purpuro8178 4 роки тому +1

    thank you so much. I have been trying to understand this for weeks, and you have explained it so much more clearly than anyone else!

  • @simoneottavianelli3250
    @simoneottavianelli3250 2 роки тому +1

    I've been looking for a well done tutorial for days. Thanks!

  • @宫赫
    @宫赫 2 роки тому

    Xcode 13.1
    Hey, I tried to write a struct to decode JSON text, I also use 'let id = UUID()', why Xcode warned "Immutable property will not be decoded because it is declared with an initial value which cannot be overwritten. Make the property mutable instead", I do not know how to solute this warning.
    But really let is right, If I use var, I must make sure there is an "id" field in JSON text and I do not set the "id" field.

    • @DesignCodeTeam
      @DesignCodeTeam  2 роки тому

      Hi, can you try with
      let id: String
      instead? Because the API already returns an ID, so you can take the ID from the API instead of assigning a UUID.

    • @shinygoldfat
      @shinygoldfat 2 роки тому

      ya I ge this same error and the code doesn't shoot out any output like what happens at the 9:45 mark of this video

  • @johnbiddulph4389
    @johnbiddulph4389 2 роки тому

    Where's the next video?

  • @brothercaleb
    @brothercaleb 3 роки тому

    7:55 the “[Post].self” is tripping me up, what does it mean to have a “.self” on the end (suffix)? (I know “self.” (Prefix) which points to the class itself)

  • @oisbelsimpsonverdecia9458
    @oisbelsimpsonverdecia9458 4 роки тому

    Hello. Can you do a video about GET or POST request to an API that the server require Basic Auth in Swift 5. There is some info about a delegate implement authentication challenge but is not clear. Thank you in advance.

  • @m__link6499
    @m__link6499 4 роки тому

    Hi dude, I buy your course which look very nice, but I have to check my mail every Time I need to sign In with the Magic link system 😥...that means I can’t watch courses on my IPad cause it not synchronize with my mail box...how can I handle that?

  • @jeremymeissner7603
    @jeremymeissner7603 2 роки тому

    Thank you so much!

  • @antonstandwerth
    @antonstandwerth 4 роки тому

    How do I implement a search bar where the result in the list are entries (which if selected, display additional information) from the API. For context, I am trying to create an app witch utilizes a dictionary API.

  • @user-rc2nt1tb2u
    @user-rc2nt1tb2u 4 роки тому

    .
    I'm trying to build an app that searches through the web (Using web scraping) and returns the specified data instantly (data can be updated on the website and I want it to be updated in my app as well), can that be done with JSON?

  • @ashim44
    @ashim44 4 роки тому

    Swift UI handle api call using combine framework. This is similar like doing old way. Would be nice if it was more declarative syntax than static functions.

  • @wolski3714
    @wolski3714 2 роки тому

    This is literally ten best tutorial on yt. With a bit of adapting its suitable for every usage. Thanks man

  • @_marlon
    @_marlon 4 роки тому

    Have you made the combine video yet and I’m just not seeing it? Or is that a video you’re working on?

  • @axtrock
    @axtrock 4 роки тому

    I don't speak English and still I understood perfectly

  • @ayushgogna9732
    @ayushgogna9732 3 роки тому

    not working for me it runs and crash at line 22 of data.swift file please help me.

  • @a3igner
    @a3igner 3 роки тому

    @DesignCode Why am i getting an error i "let id=UUID()" ? i have to change it to var id=UUID() instead... MAKE THE PROPERTY MUTABLE INSTEAD! How come yours doesnt error out?

  • @LukePlaysGames
    @LukePlaysGames 3 роки тому

    I get "Preview Crashed" whenever I try to load it

  • @saamr2012
    @saamr2012 4 роки тому

    Do you have a paid course for teaching SwiftUI + MySQL (read, write, update). I have web app and MySQL database on GoDaddy and want to connect to MySQL from IOS as well.

    • @brothercaleb
      @brothercaleb 3 роки тому

      Make an api on the server at godaddy which serves up json and it should work with this

  • @AvsSensBest
    @AvsSensBest 4 роки тому

    Yeaasssss About time, I can throw my spaghetti code in the garbage and finally move forward. Great tutorial

  • @tonisuwendi64
    @tonisuwendi64 4 роки тому

    anyone has an issue that the List empty and I check my debugging area the data load fine

  • @BranGaming20
    @BranGaming20 3 роки тому

    is that same for storyboard?

  • @brianstevens8390
    @brianstevens8390 3 роки тому

    Very well done. Thank you for this video.

  • @msvmanikantasrivishnu7788
    @msvmanikantasrivishnu7788 4 роки тому

    Hey i have windows machine and i want to use sketch can you tell me how to install the virtual mac os in windows and where to download the macos zip. I am having only ipad

  • @charlesm.1638
    @charlesm.1638 4 роки тому

    Thank you!!!!!! Your video filled the missing pieces I needed.

  • @mahanshiran5037
    @mahanshiran5037 3 роки тому

    perrrrrrrrrrrrrfffffffeeeeeect! thanks

  • @kalpeshsalvi9081
    @kalpeshsalvi9081 4 роки тому

    nice tutorial..Thank You!!!!!

  • @alanjames670
    @alanjames670 4 роки тому

    Can I use this same function to display geojson data on a map?

  • @altelasoftware2992
    @altelasoftware2992 4 роки тому

    is the next part is already up here?

  • @brotherx6205
    @brotherx6205 4 роки тому

    beautifully explained, thank you

  • @XiSlow
    @XiSlow 3 роки тому

    Beautiful and clean

  • @perrygupta
    @perrygupta 4 роки тому

    Where is next session?

  • @rovsen1993
    @rovsen1993 4 роки тому

    Very cool and interesting tutorial, man)

  • @DarbazDara
    @DarbazDara 4 роки тому

    You are the best

  • @alizaidi5610
    @alizaidi5610 3 роки тому

    Great tutorial!

  • @saulramirez727
    @saulramirez727 4 роки тому

    Amazing. Thanks.

  • @antonnekrasov5670
    @antonnekrasov5670 4 роки тому

    omg man! thx!

  • @chettodust
    @chettodust 3 роки тому

    Is the follow up to this video on UA-cam?

    • @DesignCodeTeam
      @DesignCodeTeam  3 роки тому

      The rest of the videos are in my swiftui course: designcode.io/swiftui