SwiftUI Fetching JSON and Image Data with BindableObject

Поделиться
HTML-код
  • Опубликовано: 28 ноя 2024

Комментарии • 153

  • @pasta0328
    @pasta0328 5 лет назад +1

    For anyone who’s done react native development this will actually look pretty straightforward. Minus the combine stuff depending on if you’ve done Rx stuff. Pretty cool! Thanks for putting this out there even though it’s clear that you’re learning as well. We need more of this!

  • @alexitosworld
    @alexitosworld 5 лет назад +3

    FYI, Never is Swift's bottom type, a type that doesn't have any instance (you can't create a Never). This allows us to encode in the type system that the subject can't fail. That's what you want for UI so that's why is always used in there ;)

  • @rogerwprice
    @rogerwprice 5 лет назад +6

    Wow... I'm glad you went first on this!

  • @thomasengland1701
    @thomasengland1701 5 лет назад +14

    You shouldn’t need to call dispatch. You can call onReceive. Also you should initialize the network manager in scene delegate and make it into an environmental object.

    • @tapizquent
      @tapizquent 5 лет назад +1

      Please elaborate.
      Do you have a code sample to explain this?

    • @w0mblemania
      @w0mblemania 5 лет назад +1

      @@tapizquent You need to watch all the WWDC sessions on SwiftUI and Combine. They are required viewing at this point. Cheers.

  • @JohnSeabourn
    @JohnSeabourn 5 лет назад +1

    I know this is an older video and they deprecated Bindable object but I was finally able to get my stuff working following this with Observable Object.

  • @nicwanavit5463
    @nicwanavit5463 4 года назад

    ohh man i literally struggled for days until i find this. Thanks so much :)

  • @digitalsuperman
    @digitalsuperman 5 лет назад +3

    im loving this swiftUi framework

  • @mcauslenter
    @mcauslenter 4 года назад

    Always the best content!!! Love your videos mate! Tks!!!

  • @Xenc5
    @Xenc5 5 лет назад +6

    Thank you for the insights, top quality channel 👌

  • @devsimples
    @devsimples 5 лет назад +5

    On XCode beta 4
    the variable didChange was renamed to willChange
    Thank you for the video.

  • @pasta0328
    @pasta0328 5 лет назад +12

    “Now I’m going to pray that the syntax highlighting comes back” 😂 yep sounds familiar

  • @leomike3749
    @leomike3749 4 года назад +1

    What if I want to fetch and render it into a text component, how should I do it?

  • @kingkonguae
    @kingkonguae 5 лет назад +3

    DUDE I LOVE YOUR VIDEOS!

  • @emmanuelpregnolato5026
    @emmanuelpregnolato5026 5 лет назад

    Nice tutorial as always!
    Quick suggestion.
    Instead of fetching in the init() of NetworkManager you can use, on the NavigationList or a Group surrounding the NavigationList , at the end of the brackets Group { ...}.onAppear(perform: networkManager.fetch)

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад +1

      You definitely don't want to perform a network refetch if the view appears a second time, for example when a controller is popped and shows this view again.

  • @DassineB
    @DassineB 5 лет назад

    Thanks for the video! Will this be used to reduce the amount of server load?

  • @rebeloper
    @rebeloper 5 лет назад +11

    🤟Reactive Programming 🤟

  • @curt8806
    @curt8806 4 года назад

    Hey dude. Question. Once the app loses internet what happens ? Any way you can create a tutorial on how to save the data locally so that it’s not always needing internet ?

  • @lawrencejob
    @lawrencejob 5 лет назад

    Worth noting - in the final release, Combine will mean you don’t have to add all that extra code!

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад

      Indeed I was waiting for the combine sdk to be released. Not sure how to work with publisher yet.

  • @astronomers
    @astronomers 4 года назад

    I'm trying to do a vertical scroll that makes one of the images slightly bigger when scroll stops. How do you set the feature image to appear bigger than the rest when scroll stops.
    similar to this but not exactly

  • @sreekanthzyou
    @sreekanthzyou 5 лет назад

    @State @objectbinding being used for the same requirement of observing the state of bindable object. I think we should use only @objectbinding in both the cases as we are using the variables of external types ViewModel and ImageView.

  • @chrismanhutagalung4410
    @chrismanhutagalung4410 5 лет назад

    Hello in this case using method get, and how we can post data to api?

  • @jeremydrouhin5544
    @jeremydrouhin5544 5 лет назад

    I need help ! With that Tuto, I get data after UI. For example : List(networkManager.movies.results, id: \.id) networkManager.movies.results.count = 0. I use themoviedb API. Thanks in advance !

  • @khanputty2
    @khanputty2 3 года назад

    Great job 👍

  • @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?

  • @darvikpatel
    @darvikpatel 5 лет назад +1

    Can you please make a video showing how to make draw/make shapes on swiftUI manually

  • @tonynguyendtn1984
    @tonynguyendtn1984 5 лет назад

    Question: do you like SwiftUI or is it just new framework that will be redundant in 5 years (per your earlier video)?

  • @damikdk
    @damikdk 5 лет назад +2

    May you please talk about CoreData + SwiftUI best practices

    • @sacredgeometry
      @sacredgeometry 5 лет назад +2

      The best practice is not to use CoreData. ;) haha only joking. How would it be any different to using it with UIKit/ appkit?
      Actually that said if you look at some of the patterns used with realm and RxSwift it may give you some hints. That or something like flux.

    • @dk-sky3820
      @dk-sky3820 5 лет назад +2

      *cough* Realm DB *cough*

  • @CuriosMindDIY
    @CuriosMindDIY 5 лет назад +3

    My prayers has been answered!! Lol Thank you!

    • @hannaung4281
      @hannaung4281 5 лет назад

      Lakad Matataaaag ... Normalin Normalin :3

    • @CuriosMindDIY
      @CuriosMindDIY 5 лет назад

      Han Naung I don’t get what you’re saying but I’m excited too 😂

    • @hannaung4281
      @hannaung4281 5 лет назад

      @@CuriosMindDIY 'My prayers are answered ' word is Dota2 game' chat weel . so, i thought you are the one of dota gamer 😁

    • @CuriosMindDIY
      @CuriosMindDIY 5 лет назад

      Han Naung I used to play LoL tbh hahah

  • @xxThemoritzxx
    @xxThemoritzxx 5 лет назад

    Nice Video. How can i Save those fetched JSON objects in a database like we done it in Core Data?
    Best regards

  • @TreyCox1
    @TreyCox1 5 лет назад

    Thanks again, Brian! I have my test app working perfectly with these steps. Could you possibly show how to pass this data into another view?

  • @menteb
    @menteb 5 лет назад

    Would you use the same approach to parse XML/Atom? What would be the difference in code?

  • @grenvil8414
    @grenvil8414 3 года назад

    got error in line 50
    "Cannot infer key path type from context; consider explicitly specifying a root type"
    got error in line 52
    "Cannot convert value of type 'Int' to expected argument type 'Course'"

  • @israelmanzo8725
    @israelmanzo8725 5 лет назад

    Sweet!! Thank you Brian..!

  • @dheerajbhavsar9769
    @dheerajbhavsar9769 5 лет назад

    Can you also make a video with Image Caching as well? It will be very helpful...

  • @magic0x0
    @magic0x0 5 лет назад

    Thanks for the great tutorial 🙏🏻

  • @ibrahimsalah5609
    @ibrahimsalah5609 4 года назад

    Hi Brain
    I'm found that to load with Kingfisher/SwiftUI pod
    KFImage(URL(string: course.imageUrl)!, options: [.transition(.fade(0.5))])
    .frame(height: 200)
    .resizable()

    • @ibrahimsalah5609
      @ibrahimsalah5609 4 года назад

      Also, we can load data on the list instead of binding
      .onAppear(perform: getCourses)

    • @LetsBuildThatApp
      @LetsBuildThatApp  4 года назад +1

      If you want to hit the network every time your list appears :)

  • @NTuneLabs
    @NTuneLabs 2 года назад

    Easy for you to say!

  • @kennymaes6903
    @kennymaes6903 5 лет назад

    Love Your videos and wonder if you do this the same way for core data with binding ? Thanks for all your tutorials so far

  • @opeyemiadeola3754
    @opeyemiadeola3754 2 года назад

    hello please i have a question

  • @SengchheangChhun
    @SengchheangChhun 5 лет назад

    Thank you for the video.
    I reused the ImageViewWidget in my application and wrap it with NavigationButton. Somehow the image stop appearing.
    Thank for any tips

  • @mhmtkrnlk
    @mhmtkrnlk 2 года назад

    Hail the AsyncImage

  • @TheRedEagle-0
    @TheRedEagle-0 5 лет назад

    Hey does anyone know how I could for example get a body of JSON where - lets say - the 'name' is something specific

  • @GOK1970
    @GOK1970 5 лет назад

    How to do this only with "optionals" from API ? ( let author: String? )

  • @cristhianaguilarverduguez1698
    @cristhianaguilarverduguez1698 5 лет назад

    Excellent job master =)

  • @football1606
    @football1606 5 лет назад

    Could you please make a tutorial explaining how to make the Face ID circles animation? I haven’t be able to find one.... thank you

  • @AbdullahAlsharif
    @AbdullahAlsharif 5 лет назад

    What is the name of the background tune at the beginning of the video?

  • @MrBlaq
    @MrBlaq 5 лет назад

    Question: do the views have lifecycle methods?

    • @sacredgeometry
      @sacredgeometry 5 лет назад

      As I have pointed out below
      If you look at the View documentation there is a list of view lifecycle events under the Handling view events section
      developer.apple.com/documentation/swiftui/view
      So handling the onAppear event would be something like this
      Text("Test Text View")
      .onAppear(perform: {
      print("Wooter")
      })

  • @CAHLIT0
    @CAHLIT0 5 лет назад

    Thanks for this!!!

  • @user-pr6up2vw9r
    @user-pr6up2vw9r 5 лет назад

    what is the diff between @state and ObjectBinding? They looks the same in this example.

    • @dun198
      @dun198 5 лет назад

      As far as I understood correctly, @State is for binding a local variable, while @ObjectBinding is for binding an 'external' model object. Check out WWDC 2019 Session 226 for more information (especially around 31:00)

  • @nizz4m
    @nizz4m 5 лет назад

    You're awesome man

  • @ajinkyasonar
    @ajinkyasonar 5 лет назад +1

    We all are one..
    A very humble and polite request to iOS Developers of every country, stop selling your apps at least price.We are developers and each app that we make needs efforts ,time and patience.
    We think of an idea...design UI and write code for it.After everything, we go through the stress of apple review where there are chances of approval and rejection both.On approval ,we get money and on rejection we get nothing.We are doing hard work and it needs to be appreciated, we can't compromise for less.
    A client offered 250$ for an app, later the same client offered 150$ and now asking to sell apps at 70-80$ .....This is all due to few developers have started selling apps at minimal cost like 70-80$.We need to show a little patience ,if we will adjust for 70-80$ ,then soon there will be a day when we all will loose our identity and will be suppose to sell app at 10-20$ also.
    PLEASE STOP COMPROMISING AT LOW PRICE AND LET'S GROW TOGETHER,"WE ARE IOS DEVELOPERS"!!!

  • @DigiNerd21
    @DigiNerd21 5 лет назад

    Hello, how can i pass userdata (user id) from an EnvironmentObject to the Networkmanager class? I tried to use it in the class:
    class Networkmanager: ObservableObject {
    @EnvironmentObject var userdata: userData
    and in the Url i can pass the data:
    guard let url = URL(string: "api.letsbuildthatapp.com/jsondecodable/courses/index.php?userid=\(userdata.userId)") else { return }
    It does not throw an error in xcode but wenn i start the app i get the error:
    Fatal error: No ObservableObject of type userData found.
    How can i fix it?

  • @azero79
    @azero79 5 лет назад

    it's like rxjs, or ReactiveX in general, web devs been using this for year on web apps.

    • @pasta0328
      @pasta0328 5 лет назад

      Lots of people use it for lots of things, it doesn’t come from web

  • @cularu1
    @cularu1 5 лет назад

    What's the difference between swift and swiftUI? Do we need to learn swift to use swiftUI?

    • @alirezanamazi2751
      @alirezanamazi2751 5 лет назад +1

      SwiftUI is ridiculous never go around swiftui

    • @metalsquid
      @metalsquid 5 лет назад +3

      Swift is a programming language. SwiftUI is a framework for creating the visual user interfaces you see in an iOS app. Currently we use the UIKit framework to make user interfaces in iOS, and the AppKit framework for MacOS user interfaces. SwiftUI is a brand new framework written entirely using Swift that can be used to create user interfaces across all Apple's operating systems from the Mac down to the Apple Watch. So yes, you will need to learn Swift to use SwiftUI.

    • @w0mblemania
      @w0mblemania 5 лет назад

      @@metalsquid Small correction: parts of SwiftUI are written in C++. In fact, parts of SwiftUI actually predate the creation of Swift. SwiftUI has been in development for at least 7 years, maybe 10.

    • @metalsquid
      @metalsquid 5 лет назад +1

      @@w0mblemania At WWDC they said that SwiftUI was "built from the ground up in Swift, for Swift". I took that to mean SwiftUI was written 100% in Swift. Thanks for pointing out that isn't the case. I should word it more accurately in future.

    • @w0mblemania
      @w0mblemania 5 лет назад +1

      @@metalsquid np. Apple marketing is... marketing. Apple engineers on Twitter told a different story, is all. Cheers.

  • @brazo98
    @brazo98 5 лет назад

    Thanks Dude.

  • @registered99
    @registered99 5 лет назад

    Is there a way to view this tutorial not as a video? Would be nice to see the project files or something instead

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад

      Just look in the description for the project download.

    • @registered99
      @registered99 5 лет назад

      @@LetsBuildThatApp Thanks, sorry it was a bit hard to find with all the other links in there.

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад

      Welcome to the world of spam marketing :)

  • @kheangsenghort842
    @kheangsenghort842 5 лет назад

    Cool videos :D

  • @antonzhevchenko8489
    @antonzhevchenko8489 5 лет назад

    Not working on Xcode beta 5
    Black screen occurs after loading. I've changed deprecated methods, but with no success
    Also i tried to create my project with the same code and updates for deprecated methods, but binding not working and after i receive data from JSON the @State variable not updating view((

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад +1

      Binding has changed dramatically.

    • @antonzhevchenko8489
      @antonzhevchenko8489 5 лет назад

      @@LetsBuildThatApp Yes, let's wait for stable version))
      Also Brian could you made a video about Viper pattern and rxSwift)

  • @red010182
    @red010182 5 лет назад

    how to do infinite loading using this approach?

    • @andywong3095
      @andywong3095 5 лет назад

      There are, NO, -> such method of "infinite loading", literally. (No one has a device that can store infinity number of objects)
      Someone, comes up with an approach of fetching data, to make it sound, superior, hehe. And, a lot of other coders/programmers like the term. Because, it sounds good. hahaha.
      Dart, for example, if you fetch 1000 records, only 10 items were visible on the device. It will only fetch the view box's contents. (10 items) => even IF, there exist, infinity number records, one can do continue fetching, without running out of RAM.
      That was a very old idea.
      I do not know, how SwiftUI will implement this approach. I suspect, it is the same approach.
      So, as long as you do NOT store all records, and only those in the viewBox, at any time, THEN, it is LIKE infinity loading.
      Max Int64 Integer for Swift is:
      9223372036854775807
      Is that an infinity number?

  • @AdelUI
    @AdelUI 5 лет назад

    If i want to call my api , every time when View is did appear how i can do that , in UIKit
    I use ViewDidAppear ... but what's the equivalent here ?!

    • @sacredgeometry
      @sacredgeometry 5 лет назад

      You really don't. That would be very inefficient what you want to do is to update your view every time your data changes.
      So what you could do is set up an observable that is subscribed to by your view and to emit the changes to that observable stream. That way any changes propagate to anyone that cares about it.
      SwiftUI is reactive most of the time you don't need to hook into the view lifecycle like that. That said if you look at the View documentation there is a list of view lifecycle events under the Handling view events section
      developer.apple.com/documentation/swiftui/view
      So it would be something like this
      Text("Test Text View")
      .onAppear(perform: {
      print("Wooter")
      })

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад +2

      Correct, make use of the new Reactive style programming and all will be good.

    • @AdelUI
      @AdelUI 5 лет назад +1

      Sorry .. but that fucking awesome 😍😍😍

  • @MrBlaq
    @MrBlaq 5 лет назад

    The network manager reminds me of mobx.

  • @aleksplats
    @aleksplats 5 лет назад

    Thanks :)

  • @smackaroony
    @smackaroony 5 лет назад

    luv it

  • @sasaedo23
    @sasaedo23 5 лет назад

    how to check downloaded json?
    if clauses! = nil {
    List {..}
    } Else {
    ........
    }
    the body is a mess. nenache you can create for thousands of objects !!!

  • @achieverbas6104
    @achieverbas6104 5 лет назад +4

    10:35 Please. It's a component. Please. Infact apple is calling it a component too. So no widgets please and thanks 😆

  • @mobilestar6575
    @mobilestar6575 5 лет назад

    Thank you again for wonderful video. I hate to give you only 1 like (not 10 or 100 likes ) (yes)

  • @elviss911
    @elviss911 4 года назад

    how to load array ??
    Post Parameter : ID -> 8
    Json Response:
    { "success": "true"
    "list":
    [
    {"nameCourse": "Swift",
    "imageUrl": "....."}
    {"nameCourse": "Kotlin",
    "ImageUrl": "...."}
    ]
    }

  • @davidlangley9287
    @davidlangley9287 5 лет назад

    I really want to get used to this new swiftUI but I just can't :(

  • @RatmanSays
    @RatmanSays 5 лет назад +1

    aaaand I'm sticking with regular swift and objective c, and yes even storyboards. I'll switch to react native before this lol

    • @andywong3095
      @andywong3095 5 лет назад

      Hehe, ReactiveNative Facebook's Silly things (make Mr.S/Z a Billionaire); a lot of "billionaire wannabe"s were out there! But it is too late. Native only to those wannabe's home.
      Calling something NATIVE, which is NOT native, Is it funny?
      ......AD.....AD.....AD....AD......AD.......AD.......AD.......$$$$$$$$$

  • @DimNovo
    @DimNovo 5 лет назад

    18:20 -
    Image(uiImage: (UIImage(data: imageLoader.data)) ?? UIImage(named: "Apple")!)
    just in case...

    • @elviss911
      @elviss911 4 года назад

      add image in asset with name apple, but equals dont work, i test and dont wrks

  • @saj5935
    @saj5935 5 лет назад

    game of thrones remembered 😕

  • @gummibarchen1372
    @gummibarchen1372 4 года назад

    .identified(by: \.name) Xcode 11 Beta 4 -> new Xcode 11 Beta 5 - ,id: \.name

  • @w0mblemania
    @w0mblemania 5 лет назад

    For those following along at home:
    gist.github.com/chriseidhof/2c3bcdfa5bfa0795b33bd17f1e88771d

  • @joesminis
    @joesminis 5 лет назад +1

    Followed this tutorial, but did it with the new iOS 13 update. github.com/joemissamore/SwiftUIJSON

  • @iYousef911
    @iYousef911 5 лет назад +1

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

    • @t3ix89
      @t3ix89 5 лет назад

      me too, have you find a solution ?

    • @iYousef911
      @iYousef911 5 лет назад

      Kevin Teixeira yes check out the image holder for me I forget to add the image in the assets folder

  • @rogerwprice
    @rogerwprice 5 лет назад

    Beta 5 broke things for me- working github update is here github.com/antwerpenR/pokemonListFromJSON

  • @محمدبنسراجالدين
    @محمدبنسراجالدين 5 лет назад

    Apparently no one knows how to create a list with dynamic sections And delete rows functionality. Like a list of employees sectioned by departments and still can delete rows!!
    Can you?!

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад +1

      Wait for it to come out of beta before you blow a gasket :)

    • @محمدبنسراجالدين
      @محمدبنسراجالدين 5 лет назад

      Lets Build That App interesting. Never thought it could be a bug. Just thought it’s too hard to implement!
      Thanks a lot, life is good again 😁

  • @YoYoYo
    @YoYoYo 5 лет назад +1

    This is looking like a nightmare.

  • @phanirithvij
    @phanirithvij 5 лет назад

    Looks like Flutter. Don't hunt me down. I don't have a Mac I'm not rich.

  • @juliocesartorrescama5661
    @juliocesartorrescama5661 4 года назад

    outdated :(

  • @Th3DadGam3r
    @Th3DadGam3r 5 лет назад +1

    Jeez, now trying to load an image. There’s a lot of, “I don’t know why I do this’

    • @andywong3095
      @andywong3095 5 лет назад

      Why? Beta Xcode Beta MacOSX........ BETA?

  • @ghandn
    @ghandn 5 лет назад +1

    You should make a paid course for swiftUI at some point that goes more in depth on the framework. The way your videos are now I would love going through a class taught by you!

  • @Th3DadGam3r
    @Th3DadGam3r 5 лет назад

    BANG operator is called a force unwrap...

    • @andywong3095
      @andywong3095 5 лет назад

      "Just a software developer and game enthusiast" will know, what is TRIVIAL. and tomato vs toMAto.

  • @Th3DadGam3r
    @Th3DadGam3r 5 лет назад

    Maaaate wtf got to you setting the didSet. You clearly don’t know what you’re doing. Your passing self to a state object, this is a retain cycle? Never, means that there isn’t ever going to be a failure case in the network manager. Which clearly isn’t true. As it’s a network/JSON parser....
    You’re also capturing self in your network completion........
    Oh god, now he’s used a force unwrap on the JSON parser.
    I advise no one to follow this video...

    • @andywong3095
      @andywong3095 5 лет назад

      if aJsonObject.Result != nil // SUPERIOR PROGRAMMER. (really not too much real world experiences)
      ObjC, that is more relevant. With managed framework, aka UWP, DART, and Swift, very little to worry about.
      One will know, when ever there is a leak. Hint: Instrument.
      Please DONOT scare newbie, with this phrase. hehe.
      Disclaimer: I am a silly old man.

    • @CihanBoz
      @CihanBoz 5 лет назад +1

      I am sorry, but this guy is right, even though you are making fun of him in your other video. I respect your work and
      your videos are helpful, when you are experienced enough to see that your code is often quick & dirty . But please be aware that most of the people watching your video aren't experienced iOS devs or devs at all. You should be always a good role model and assume especially beginners are gonna take your code as it is, as someone who sells paid courses you should take more responsibility IMO.

    • @andywong3095
      @andywong3095 5 лет назад +1

      Hi Mr@@CihanBoz , Sir, let me be clear, I AM NOT J from N, friend of MR.B.
      I have been, writing programs for 45+ year, never stopped. Yet, I am very impressed with Mr.B's ability to demonstrate the concept, in real time. If you were, like me, retired, wasting time watching a lot and a lot of YT tutorial and read literally many hundreds of GitHub projects, THEN,
      you will agree with me, Mr. B is one of the best. Unless, you yourself, were J from N. His competitor.
      Pls, do not take me, seriously.
      Human, the nature is lazy and sloppy. Men, Programmers more so.

    • @Th3DadGam3r
      @Th3DadGam3r 5 лет назад +1

      Andy Wong just do if result = aJsonObj3ct.result {} then as it’s cleaner. Or use guard.

    • @Th3DadGam3r
      @Th3DadGam3r 5 лет назад +2

      If your doing tutorial videos you should be striving for best practices as people will just copy your code verbatim. It’s important to understand the concepts and not pickup bad habits.

  • @GooseZero
    @GooseZero 3 года назад

    Great video, but it's a bit outdated. I'd recommend watching this and using HackingWithSwift's "How to use @ObservedObject to manage state from external objects" page for a companion on how to use the current method. It's much simpler now!