Introduction to SwiftData (WWDC23)

Поделиться
HTML-код
  • Опубликовано: 19 июл 2024
  • Learn about CRUD in SwiftData. Create, Read, Update and Delete your data models. Models are defined in code with the @Model macro. We also discuss the @Query property wrapper to fetch data.
    🚀 LaunchBuddy: apple.co/3iFcjjW
    📚 Try CWC+: bit.ly/cwc_flo
    ☕️ Buy me a coffee: ko-fi.com/flowritescode
    SwiftData Documentation: developer.apple.com/documenta...
    👋 Links: flowritesco.de
    🛠 Forge: apple.co/3riG8MQ
    Affiliate Links ❤
    📕 SwiftUI & Combine Books: www.bigmountainstudio.com/a/t...
    🔬 Get Reports about your apps: appfigures.com/r/5by3g
    📊 Privacy focused analytics: dashboard.telemetrydeck.com/r...
    💻 The most powerful mac app for developers: devutils.app/?ref=flo
    ☕️ Support me: ko-fi.com/flowritescode
    If you have any video suggestions please feel free to let me know by a comment.
    Get in contact via
    Twitter: / flowritescode
  • НаукаНаука

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

  • @FloWritesCode
    @FloWritesCode  Год назад +1

    Do you already have ideas what to do with the new APIs? Make sure to actually work on them with LaunchBuddy: apple.co/3iFcjjW

  • @toastrecon
    @toastrecon Год назад +7

    Oh man. This makes me so happy. I’ve hated Core Data with a passion.

  • @StewartLynch
    @StewartLynch Год назад +10

    Nice. Looking forward to seeing how we can handle more complex models with relationships

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      That's also really simple, thanks to the @Relationship Macro. Just a single macro to add relationships (and unique properties, etc.).

  • @kosnowman
    @kosnowman Год назад +1

    wow that's look simple to get started thank you!

  • @codybontecou
    @codybontecou Год назад +6

    Nice. I'm glad you got this out so quickly. Looking forward to the rest of the WWDC dev updates coming out.

  • @arukshun2710
    @arukshun2710 Год назад +1

    Thanks for sharing this information. I watched wwdc and was most excited by this announcement.
    I'm working on my first real app from scratch, for learning purposes. It's been a fun journey, but while i really liked the technology behind coredata, i hated working with it in combination with swiftui because I often felt like i was fighting with the language/frameworks to get stuff done. This seems to fix all the things i didn't like doing, and i didn't even need to ask! I chose a great time to start learning ios development.
    Gonna try to redo the data layer in my little app now to further understand how this works. The information in your video gave me the skills i needed to understand what to do next. Cheers!

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      Have fun in your development journey! Just letting you know that I made a free app to manage app ideas & updates in case you want to get some help on the way :D It's called LaunchBuddy, you can get it right in the App Store.

  • @mattheaney729
    @mattheaney729 Год назад +1

    Great video! And unbelievable speed to get a video on this topic up already. Thank you so much! I've seen a few other quick tutorials showing the save functionality too, so will be interesting to see in what situations (if any) it's needed now.

    • @FloWritesCode
      @FloWritesCode  Год назад

      Glad you enjoyed it! I've also seen an article you "modelContext.save()", but from my testing it just wasn't needed.

    • @mattheaney729
      @mattheaney729 Год назад +1

      @@FloWritesCode It looks like the default configuration for the ModelContainer has auto-saved enabled. Apple say in there docs it checks periodically for updates to save in that case (doesn't say how often), so maybe save is only needed for instant saving or when auto-save isn't enabled (I'm still looking into this, so might not be 100% accurate lol)

  • @Disfuncionario
    @Disfuncionario Год назад +2

    It’s so easy, cleaner than CoreData. But I would like to have more segregated the data. For example putting the persistence logic in the Observable rather than in the view. Another thing is that the model is a class not a struct.

  • @30guarino
    @30guarino Год назад +2

    Flo....thanks for the early update and great video!........ was just wondering if you can just increase your text size to eliminate the zoom zoom zoom zoom zoom lol

    • @FloWritesCode
      @FloWritesCode  Год назад

      Thank you, I'll try to reduce the amount of zooming (it happens automatically through my screen recorder when I click somewhere - this eliminates my need of editing the video).

    • @30guarino
      @30guarino Год назад +1

      @@FloWritesCode gotcha… makes sense!

  • @profgallaugher
    @profgallaugher Год назад +1

    Thanks for getting this up & running. I'm finding LivePreview is crashing, but build & run in the simulator works fine. I'm assuming you'e seeing the same thing since you ran in the simulator. Is this correct & a limitation in the first Xcode beta? Really appreciate your video! There are so many small details missing from the first-day blog posts that you cover. This was really wonderful. Keep at it! Can't see what you do with the Firebase stuff in a few weeks after you've had a chance to sift through all of the advancements.

    • @FloWritesCode
      @FloWritesCode  Год назад

      Thanks, seeing your comments always puts a smile on my face :)
      Yes, I have experienced some crashes with the Preview, e.g. when trying to delete an object through the modelContext. I would expect this to get fixed in one of the next beta versions of Xcode though.
      Swift Macros could be super-duper interesting for Firebase Firestore - A few months ago I created a system that keeps objects in sync with Firestore without SnapshotListeners + supporting ObservableObject. Now this entire thing could potentially get turned into a single Swift Macro and make our lifes so much easier. That's a project for future-me though ;)

  • @brucknerdevilliers
    @brucknerdevilliers Год назад +1

    Nice work. Thank you. I injected what I use for CoreData: print(URL.documentsDirectory.path) in a .onAppear modifier and tried to follow the path in Finder, but the final Documents folder is empty. Do you know how I can access the sqlite3 file/table?

    • @FloWritesCode
      @FloWritesCode  Год назад

      SwiftData still uses a sqlite file, but it now has the .store extension. Stewart Lynch recently tweeted about this, you can have a look at this Twitter to find out more :)

  • @wukerplank
    @wukerplank Год назад +1

    Very good primer! I'm curious how they solve schema changes and migrations 🤓

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      Apparently they work "out of the box", but we need to invest some time to thoroughly test this, I agree!

  • @ColeDano
    @ColeDano Год назад +1

    This is exciting! Even if it's just an wrapper for CoreData, it feels so much more SwiftUI.
    Was the tool for downloading Xcode Xcodes? No link in the video.

    • @FloWritesCode
      @FloWritesCode  Год назад

      Yes and yes! The video is linked as an info card in the top right corner while I speak about it, here it is again: ruclips.net/video/EjBTkq-wtCE/видео.html

  • @malamin
    @malamin Год назад +1

    Great video!! Stupid question: Does this replace or eliminate the need for CoreData?

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      SwiftData is only available on iOS 17, so if you want to make apps that target earlier versions you can only go with CoreData (or other frameworks).

  • @glaiveking2530
    @glaiveking2530 Год назад +1

    Hi, I'm still in my training phase and just finished building a few basic apps. I am about to start Core Data and wondered whether this will make it redundant. Overall, does knowing old things benefit my skillset in any way with how often things are getting deprecated? Or is it completely fine to learnd everything I can?

    • @FloWritesCode
      @FloWritesCode  Год назад

      Congrats on starting iOS development! You have a fun journey ahead :)
      It really depends on what you plan on doing, but generally it doesn't hurt to know CoreData, especially with SwiftData being iOS 17 exclusive and it being based on CoreData internally.
      Imagine you want to support iOS 16 in your apps - you simply can't use SwiftData in that case.
      Personally I care most about the fun of development & building my own indie apps, which is why I jump on the trend of new frameworks asap. But if those weren't my priorities I wouldn't even look into SwiftData for another year or so.

  • @rossemerson2633
    @rossemerson2633 Год назад +2

    So no more handling optionals?

  • @OttoFaerber
    @OttoFaerber Год назад

    Super, almost as simple as 40 years ago in other systems, can you now also work reasonably with date and time?

    • @FloWritesCode
      @FloWritesCode  Год назад

      Using Date is supported out of the box with SwiftData, yes.

  • @noamif
    @noamif Год назад +1

    How are you already up with videos?
    good job mate

  • @LexicalNoScope
    @LexicalNoScope Год назад

    Can this be used with MVVM? I have a project I’ve been working on for quite a while with over 100 views using @fetchrequest and some views have gotten huge and hard to manage. I tried the mvvm approach of fetches in the view models and every approach I tried wouldn’t work while some views kept the fetch request property wrapper. It would work on an initial view, then as soon as I would go to another that used a fetch request in a view or vice versa, it would crash and say fetch request must have an entity even though all the code was correct and I was passing the exact same instance of the managed object context to the views and view models. Doing it all in views where I can’t abstract away much of the logic has made this project very difficult to work on.

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      SwiftData works with MVVM, you can also fetch data using a FetchDescriptor. The only thing that doesn't work is the Query property wrapper auto-updating your Views. You will have to somehow implement that yourself.

  • @franksolleveld2909
    @franksolleveld2909 Год назад

    I wonder if there is a way to have that Query inside an Observable View Model

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      Yes and no. The Query PW is meant for Views only, but FetchDescriptors can be used anywhere to fetch data. They won't update live (as Query does) though. A video on SwiftData with & without MVVM will be out in the coming weeks.

  • @azamsharp
    @azamsharp Год назад +1

    Does it persist data when running in Xcode Previews?

    • @FloWritesCode
      @FloWritesCode  Год назад

      No - how would that even work? I actually even got a crash in the preview when deleting an object...

    • @mohammadazam3177
      @mohammadazam3177 Год назад +2

      @@FloWritesCode Hmm weird! I used it with Core Data all the time. I just injected the Environment(managedObject) into the Previews.

    • @mattheaney729
      @mattheaney729 Год назад

      You can create a ModelContainer which uses in-memory data which can be used in the previews. The WWDC video on building a full app with SwiftData shows a good example of it (about 9 minutes into the video). It doesn't persist the data, but can be used to try adding, updating, deleting etc

    • @scollaco1027
      @scollaco1027 Год назад

      @@FloWritesCode Maybe this crash is related to this issue described on the XCOde 25 Beta Release Notes?
      "After deleting an item, SwiftUI may attempt to reference the deleted content during the animation causing a crash. (109838173)"
      "Workaround: The workaround is to explicitly save after a delete."

  • @thegering
    @thegering Год назад +1

    getting a bit dizzy from all the zoom in and outs oO

    • @FloWritesCode
      @FloWritesCode  Год назад

      Sorry, will tone it down a bit in future videos! (it happens automatically through my screen recorder when I click somewhere - this eliminates my need of editing the video).

  • @tekilla79
    @tekilla79 Год назад +1

    U are zooming like a crazy

    • @FloWritesCode
      @FloWritesCode  Год назад

      Sorry, will tone it down a bit in future videos! (it happens automatically through my screen recorder when I click somewhere - this eliminates my need of editing the video).

  • @vanylaskywalker
    @vanylaskywalker Год назад +1

    Hi, nice video but I find the constant zooming and panning annoying. Thanks :)

    • @FloWritesCode
      @FloWritesCode  Год назад

      Noted! (it happens automatically through my screen recorder when I click somewhere - this eliminates my need of editing the video).

  • @asigivati1382
    @asigivati1382 2 месяца назад +1

    great video. but if possible - please stop with the zoom in and out thing, it's VERY annoying ❤ i had to stop watching.
    most of the people (like me) are watching these vids through mobile phone, so the best is to keep it with zoom in and thats it.

    • @FloWritesCode
      @FloWritesCode  2 месяца назад

      Thanks! The zooming is greatly reduced in my newer videos (this one is almost a year old).