How to use @AppStorage in SwiftUI | Bootcamp #52

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.พ. 2025
  • In iOS applications, we can use App Storage / User Defaults to save small pieces of information that will persist between sessions. This means that if a user closes the app and re-opens it, these values will still be saved! The @AppStorage property wrappers lets us easily add and save data into UserDefaults. In this video we will first understand how UserDefaults work and then look at the subtle advantages that the App Storage property wrapper gives us.
    Next video: • Manage user onboarding...
    Last video: • How to use @Environmen...
    🤙 WELCOME BACK 🤙
    WEBSITE: www.swiftful-t...
    DISCORD: / discord
    GITHUB: github.com/Swi...
    SAY THANKS: www.buymeacoff...

ความคิดเห็น • 62

  • @backlitdigitizer8628
    @backlitdigitizer8628 3 ปีที่แล้ว +31

    Literally the only SwiftUI videos I can sit through end to end. Clear, concise, but not presumptuous. Great stuff.

  • @WendyWhite-s5q
    @WendyWhite-s5q ปีที่แล้ว +3

    Don't stop doing this, you're the best. I hope you earn yourself tons of cash with those videos.

  • @jonewc
    @jonewc ปีที่แล้ว +1

    Thank you for creating such a comprehensive (and free) set of courses. I've tried several courses throughout the past years (some of them paid) and yours are by far the easiest to follow. I now use your playlists as a reference as I build my apps. Thank you, Nick!

  • @JoelFuchs
    @JoelFuchs ปีที่แล้ว +2

    Fantastic! Over the past year I worked though several paid courses and was never introduced to this and many other useful techniques introduced in this series! This series is so good I am now using it along with Nick's Swift Basics to help teach my daughter the fundamentals of coding.

    • @SwiftfulThinking
      @SwiftfulThinking  ปีที่แล้ว +2

      It is incredibly rewarding to see comments like this! I really hope your daughter is able to follow along and grasp these concepts too. You'll have to let me know how she does! Thanks for the comment Joel 👍

  • @olepetersen4460
    @olepetersen4460 3 ปีที่แล้ว +5

    Great. I think it is nice that you show that AppStorage is much leaner and cleaner than the older UserDefaults way. Thanks again!

  • @trevorduersch2278
    @trevorduersch2278 2 ปีที่แล้ว +2

    Yes, I love the examples and real-world application you demonstrate in these videos. Great stuff indeed! :)

  • @faengelm
    @faengelm ปีที่แล้ว +2

    @16:00 Thanks for pointing out that the "@AppStorage.." line needs to be in every view that wants to use the stored value.

  • @danuff
    @danuff 3 ปีที่แล้ว +4

    Thank you for making this clear and easy to understand.

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +1

      You're welcome Danny. Thanks for watching!

  • @varunbagga9996
    @varunbagga9996 ปีที่แล้ว +1

    Your content is blessing to community❤

  • @rachitsharma8829
    @rachitsharma8829 ปีที่แล้ว +1

    Great Video and clear explanation ... loved it .. ❤ .. keep it up.

  • @toomee4674
    @toomee4674 2 ปีที่แล้ว

    This is the best opening, I've ever heard 🤘I never skip it.

  • @nurlanakylbekov7266
    @nurlanakylbekov7266 3 ปีที่แล้ว +9

    Start watching from 13:22)

  • @jordanchan8881
    @jordanchan8881 3 ปีที่แล้ว

    SwiftUI is much more powerful, thanks for the video

  • @keycheung6898
    @keycheung6898 ปีที่แล้ว

    真的是太棒了!!This is awesome course!!!!ever!!thanks Nick!!!thanks

  • @kal5211
    @kal5211 ปีที่แล้ว +1

    My man.

  • @melmandaragrows
    @melmandaragrows 2 ปีที่แล้ว +1

    I did your dog gram course and use my and wished you had an updated course with FirebaseAuth and using Firestore database 😢 This is gold though🎉

    • @SwiftfulThinking
      @SwiftfulThinking  2 ปีที่แล้ว +1

      I have a Firebase playlist coming in a few weeks 🤙

    • @melmandaragrows
      @melmandaragrows 2 ปีที่แล้ว

      On Udemy** Great! Excited🔥

    • @satyadodda2386
      @satyadodda2386 2 ปีที่แล้ว +1

      @@SwiftfulThinking Waiting

    • @melmandaragrows
      @melmandaragrows ปีที่แล้ว

      @@SwiftfulThinking waiting patiently 😩😇

  • @christianburrus
    @christianburrus 3 ปีที่แล้ว +3

    Great video. I'm struggling to figure out how to use app storage for an array of strings ..... any thoughts? Thanks!

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +1

      You need a quick extension for that: stackoverflow.com/questions/63166706/how-to-store-nested-arrays-in-appstorage-for-swiftui

  • @bharathiganesh2053
    @bharathiganesh2053 ปีที่แล้ว

    Thank you🙌

  • @yuchen3587
    @yuchen3587 2 ปีที่แล้ว +1

    Great tutorial! I want to wrap my object data into JSON files and stores them in local storage, do you have a tutorial for that?

  • @vanichdrive
    @vanichdrive 8 หลายเดือนก่อน

    Good day, Nick! Thanks a lot for such a beautiful video. Do you have, by any chance, a video about offline storage but for big data? Right now I'm building the App for the gym, and I want to store inside my app GIFs that will show the user their exercises, and I want to let my users access them in offline mode. , thank you in advance!

    • @SwiftfulThinking
      @SwiftfulThinking  8 หลายเดือนก่อน

      Yes, for images/videos I would save them in the FileManager and for other data I would save them in Core Data. Both are covered in the Continued Learning playlist, or you can search for them here: www.swiftful-thinking.com/search

    • @vanichdrive
      @vanichdrive 8 หลายเดือนก่อน

      @@SwiftfulThinking Thanks a lot , and good luck ! You are the best !

  • @knowledgeispower4953
    @knowledgeispower4953 ปีที่แล้ว

    Awasome Bro...😎

  • @andrews13
    @andrews13 2 ปีที่แล้ว

    Perfect!

  • @mig12394
    @mig12394 3 ปีที่แล้ว +2

    Cool

  • @1slyboy
    @1slyboy ปีที่แล้ว

    How do you force quit of the app in the simulator? Shift-Cmd-H followed by 2nd H just minimizes the app, but when you double click to restart the app the data is still there ("Nick") before any of the code has been added yet to persist it (e.g. 8:35)?
    OK - I figured it out. After dragging it up. Long click and hold the corner of the app. Then you can swish it up to quit.

  • @saraghanavati7899
    @saraghanavati7899 3 ปีที่แล้ว +2

    I watched your instagram video on the Udemy website. Its a great and wonderful video. May you please published the second video to complete instagram format such as follower and other features? Thank you for your teaching and your videos.

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +1

      Thanks Sara! I will be creating a new Firebase series + course on this channel in the coming weeks and will be sure to include that. Thanks for watching :)

    • @coffeeCatPeanutDust
      @coffeeCatPeanutDust 3 ปีที่แล้ว +1

      @@SwiftfulThinking Just bought the Udemy course! You should totally mention this in your videos. I didn't know you had one.

  • @natgenesis5038
    @natgenesis5038 2 ปีที่แล้ว

    12:00 reference
    16:15

  • @rajdhakate617
    @rajdhakate617 2 ปีที่แล้ว

    Can I use AppStorage from inside my ViewModel? If not, what is the best way to achieve the same result?

  • @fredflintstone2460
    @fredflintstone2460 ปีที่แล้ว

    This seems to be similar to using a pointer

  • @WilliApple
    @WilliApple ปีที่แล้ว

    Is it possible to get the same @AppStorage from a different script?

  • @dimflash1987
    @dimflash1987 3 ปีที่แล้ว

    Cool!!!!!!!!!!!!!!!

  • @ejjjjjjjjjh
    @ejjjjjjjjjh 3 ปีที่แล้ว

    How can I save a COMPUTED variable to app storage?

  • @JemmaGuaney
    @JemmaGuaney 9 หลายเดือนก่อน

    13:08 : tutorial begins

    • @zenBoy323
      @zenBoy323 2 หลายเดือนก่อน

      incorrect, it begins at 00:00 because this is a beginner course and I'm pretty sure most of us didn't know about UserDefaults in UIKit and it's a pretty important thing to know where @AppStorage originated from.

    • @JemmaGuaney
      @JemmaGuaney 2 หลายเดือนก่อน +1

      @@zenBoy323 A beginner course in SwiftUI is not the same thing as a beginner course in Swift.
      Many come from Swift.

  • @Adventurevictoria
    @Adventurevictoria 3 ปีที่แล้ว

    Just quick question @AppStorage working out side of View for example ... Does this work in @main Class ?

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +2

      I believe the correct usage of @AppStorage is only used inside a View. You can just access UserDefaults directly if you need to do it in the @main struct.

  • @hashcat5721
    @hashcat5721 ปีที่แล้ว

    It should be noted that you should not store authorization and confidential information in this storage, because it is possible to get access to them.

  • @valerieokelly6224
    @valerieokelly6224 2 ปีที่แล้ว

    👍👍

  • @pakaponwiwat2405
    @pakaponwiwat2405 ปีที่แล้ว

    Hi, Excuse me.
    Does anyone know why when I try to use @AppStorage, there is always an error message saying 'Struct 'AppStorage' cannot be used as an attribute'.

    • @brandonhopkins3438
      @brandonhopkins3438 ปีที่แล้ว

      I had the same thing and realised that I named my struct AppStorage(). If you change your struct name to something else and the corresponding preview name, you'll be good to go.

  • @Horizon-tr6iy
    @Horizon-tr6iy 2 ปีที่แล้ว +1

    3:45

  • @valentinberg7
    @valentinberg7 3 หลายเดือนก่อน

    9:00

  • @nurlanakylbekov7266
    @nurlanakylbekov7266 3 ปีที่แล้ว +3

    I think if ppl interested in using and learning @AppStorage, they probably already know what is exclamation mark and they already know how to safely unwrap optional😏 Anyway thanks for the video

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +1

      Hey Nurlan! You're probably right haha. Thanks for watching!

  • @loliconmaster7152
    @loliconmaster7152 ปีที่แล้ว

    Am I the only one who gets sleepy when watching coding courses?
    It's not about the instructor, this one is great, but in general, I get sleepy when watching a programming course even if I'm coding along with the course😴

    • @zenBoy323
      @zenBoy323 2 หลายเดือนก่อน

      I get pumped and excited because I'm pretty passionate about learning this stuff! Maybe this just isn't your thing or if it is either watch courses earlier in the day or drink some strong coffee lol

    • @hasanato-01
      @hasanato-01 2 หลายเดือนก่อน +1

      @@zenBoy323 I wonder if it's really my thing cuz I've been programming for almost 4 years now yet I still get sleepy when watching a course