iOS 13 Swift Tutorial: SwiftUI and Core Data - Build a To-Do List App

Поделиться
HTML-код
  • Опубликовано: 15 сен 2024
  • Learn how to bring together Core Data (data persistence framework from Apple) and SwiftUI by building a simple To-Do list app from scratch.
    ➡️ Tutorial Files: / xcode-project-to-29153940
    ➡️ Related Tutorials:
    Understand SwiftUI: • iOS 13 Swift Tutorial:...
    Core Data: • iOS Swift Tutorial: Ge...
    🛒 GAME DEVELOPMENT COURSE - JUST $20 🛒
    www.udemy.com/...
    👏 Support me on Patreon: / brianadvent
    ➡️ Web: www.brianadvent...
    ✉️ COMMENTS ✉️
    If you have questions about the video or Cocoa programming, please comment below.
    #swiftui #swiftlang #iosdev

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

  • @JN-wj5tj
    @JN-wj5tj 4 года назад +33

    There's a plethora of SwiftUI how-to videos and sites, the bulk of which are incomplete, wrong, or poorly made presenting half-baked solutions. Brian's videos are thorough with a great amount of knowledge shared. Thanks Brian!

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

    Rock Solid, thanks! Actually a lot of the code you write, now comes default in Xcode 12

  • @simonbachmann2120
    @simonbachmann2120 4 года назад +3

    Great tutorial thank you! I'd love to see an advanced tutorial on core data where you deal with many-to-many relationships, update data and query only a subset of items from the core data.

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

    Please, I have looked everywhere on how to properly change NavigationView/List background Color in SwiftUI, Thanks to Brain for another wonderful tutorial.

  • @shonifari5783
    @shonifari5783 3 года назад +1

    22:47 This is a Great tutorial and if u had the same problem as me here I found the solution
    The problem was that my ForEach was working and display as many rows as elements in my CoreData Model, but each label was set with the first element.name .
    So the values were there but the loop didn't iterate properly.
    The solution is that in the example above, you need to change "ForEach(self.toDoItems)" to " ForEach(self.toDoItems, id: \.self)".
    IIwasn't required at the time the video was recorded or it might be that my structure requires it.
    Nevertheless this tutorial is still one of the most complete on the topic and if you found my same problem, hope my comment can help you! much love people

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

    Hey Brian, thanks for this video.
    This tutorial is crazy useful.
    But I need some help.
    In my use case, I have to put the TextField below the ForEach (Just switch the places of TextField and ForEach).
    Now, whenever we add a new ToDo item, the TextField goes down (Just like Apple’s Reminders app).
    If the app has many toDo items, the keyboard covers the TextField when the keyboard appears and we can’t see the TextField.
    What I want to know is how to automatically scroll the List ( move the view up) to see the TextField when keyboard appears.
    Please help me.
    Thanks for reading my long comment. Have a great day.

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

    YOU ARE MY CHAMP. I did not have a chance yet, but I will be viewing it this week

  • @bibochip1
    @bibochip1 4 года назад +3

    I already do like above, but my simulator just display a blank screen?

  • @toastrecon
    @toastrecon 4 года назад +5

    Strange. I get the error:
    Value of type 'NSManagedObject' has no member 'createdAt'
    Value of type 'NSManagedObject' has no member 'title'
    On the "ToDoItemView" line in the ForEach loop. Any ideas? The add button works, and the number of to-do's increases, but that one piece isn't working.

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

      I have the same issue

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

      Same here. macOS 10.14.6, Xcode 11.0 (11A420a)

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

      Saaammmeeeee

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

      stackoverflow.com/questions/59061270/swiftui-foreach-of-fetchedresults-gives-the-error-value-of-type-nsmanagedob

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

      CoreData in SwiftUI tutoríal : ruclips.net/video/X2qeZj0Xzrs/видео.html

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

    Xcode 11.5 - it is not necessary to modify SceneDelegate.swift, context and contextView are defined.
    If you are bothering with the dysfunctional preview, see stackoverflow.com/questions/59514875/swiftui-coredata-crashes-preview .
    If you want to use the folding ability of Xcode: Menu - Editor - Code Folding - Fold, and there you also find the keyboard shortcuts
    Foremost, THX!

  • @gaetanocerniglia2635
    @gaetanocerniglia2635 4 года назад +2

    Having a reference of the model inside the ContentView (controller) is not agains a clean architecture?

  • @jta7
    @jta7 4 года назад +6

    I am so confused. My code looks exactly the same to yours but on line 43, I’m getting an error saying ‘Font’ is not convertible to ‘Font?’

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

      Same problem here...

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

      @@praetoriancze Update** Watching the video a fourth time I noticed I'm using an updated version of Xcode 11.3.1, and it adds extra code in the SceneDelegate.swift. I'm still researching what effect this would have on the code** I've run into the same issue, I haven't been able to find the solution yet unfortunately :(

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

    Excellent video, a very well done tutorial. Had to pause a few times to let stuff sink in, but that’s my brains limitation, not a fault of yours :). SwiftUI looks to be pretty powerful, and the more I learn about core data the more I like it.

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

    Thx for this amazing tutorial. Would Love to See an App which is communicating with the Apple Watch, maybe as an Extension on this App. Keep up the good work.

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

    Very good tutorial and I like the way you use this extension for the FetchRequest 👍🏼 One question though, I did some trainings on Core Data and on fetching and decoding JSON data now but I love to see an tutorial on fetching JSON and storing it in Core Data (preverably with more then one entity with a relation). Do you have such a tutorial or plan to make one in the near future? In any case, thanks again man! Very clear tutorial

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

    Cool stuff. Thanks Brian.
    I think I understood how to add and delete an item. But how to modify an item, e.g. in the same view which I use for adding items? I cannot realize a cancel button to abort the modifications I already typed into the field. Any help for me? Rgds, Martin

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

    Do more more more Swift UI tutorials!!!!!

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

    Very nice tutorial.
    Saves me a lot of work to make the app working :)
    Keep up the good work :)

  • @wilfriedschulze9015
    @wilfriedschulze9015 4 года назад +3

    your tutorial is really great. I tried your To-Do List App with Core Data, it works very well. But then I tried to work with Core Data using the cloud kit. I just marked the Core Data in Cloud Check (creating the App). Now I have the problem the App will not work, because there is a crash in beginning the app. I get a signal SIGABRT in the second line of ContentView (the line with @FetchRequest(fetchRequest ...) Is there anything else to change to store the data in the cloud?

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

      having this issue too

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

      stackoverflow.com/questions/62676987/could-not-cast-value-of-type-swift-optionalswift-anyobject-to-nsfetchreques found this on stackoverflow. You have to add @objc(ToDoItem) above the class declaration of ToDoItem

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

      @@Nik6644 Genius!

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

      @@Nik6644 bro you saved my life

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

    I don't have the same file system you do, so it is impossible to proceed. I think it is good idea to mention which Xcode Version you using. I am using Xcode version 12.4.

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

    Really awesome video made for core data along with swift UI

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

    Thank you thank you for explaining what you were doing while you were doing it ! Thank you

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

    hey brain, thank you for your tutorial its substantially helpful. i have a problem here with the app, so it keeps crashing for this reason" could not cast value of type 'Swift.Optional' (0x7fff89e42578) to 'NSFetchRequest' (0x7fff89e42618)". i tried to lookup solution or updates but couldnt find any! help me please.

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

      This might help stackoverflow.com/questions/53690712/no-nsentitydescriptions-in-any-model-claim-the-nsmanagedobject-subclass

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

    any github repo to see the code?

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

    Great stuff!! I like it and helped me a lot to get a quick understanding. Is the preview crash fixed (after adding the fetch request)? Would be great to see it in the preview together with coredata!

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

    IDK why this is happening, but when I add a new task, unlike your video, the new row is being added upper the previous row, not beneath the last row.
    I have been keeping watching this video again and again what mistake I made, but still can't find it...
    Can someone drop me an idea or words that might be causing this error? Thanks;)

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

    How would you implement the EditButton() for a UITableViewController? I can't find any documentation on that, so if you could help out it would be really apprecited! Keep up the great videos

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

    Do you have any tutorial for storing a simple file on iCloud Drive folder using filemanager

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

    Thank you Brian for another amazing tutorial🙏

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

    Hey I was trying to make this into a tab in one of my tabbed views but I don’t know what I have to change I the root hosting to do that

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

    Love it keep up the good work Brian.

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

    You had me... until you wrote that "ToDoItem" function, Jesus. Things like that intimidate me and make me question if I'm even smart enough for this.
    Either way, great video and everything was definitely well explained - I just need to learn a little more Swift / Xcode before biting off more than I can chew I think, lol.

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

      Hey Karsen, you are definitely smart enough and absolutely right. If you are a beginner, CoreData can be a little bit intimidating because of all the new terms and concepts that you need to deal with. But keep pushing and you’ll get that hang of it!

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

    This is an excellent video. Very helpful.

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

    I got that error yesterday after implementing an environment object to my view. the way I fixed it was passing an environment object to the preview. Maybe if you pass a nsmanagedobject the canvas will work..?

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

    This is really cool. U r so brilliant. I think this is the big help to know about CoreData and SwiftUI. I appreciate it. Ive been waiting to watch ur brand new tutorials. 🤗🤗🤗

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

    If you want to change an item in the ToDoItemView (lets say the title), it is not reflected in the UI. Even though it is stored in CoreData. You have to somehow bind the toDoItem in order to see the changes. How would you do that?

  • @JN-wj5tj
    @JN-wj5tj 5 лет назад +1

    Great job! Thank you!

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

    Well content with cool explanation, thanks bro

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

    Hi Brian, really appreciate the video. I'm not used to the view having direct access to a database service (context). Not sure what a good structure is for SwiftUI apps. I'm currently trying to use a MVVM structure.

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

    Brian thank you for the video.One question why do you have to put .navigationBarTitle on the curly braces of the list instead of the last curly braces of the navigationview that's where makes more sense since the title is to be set to the navigation view and not the list? thank you

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

    what is the difference between a view controller and a content view I am confused if I have to use a content view instead?

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

    Hi Brian,
    Thank you for the tutorial. I was wondering if you could update your "Complex SwiftUI" tutorial for Xcode beta 5. It became broken in beta 3. I have been trying to fix it for the last few weeks but I am new to this and I can't figure it out.

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

    Man, thank you so much! You are very very appreciated my brother. Much love

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

    Awesome video, short and to the point -- thank you! One question: Is there a particular reason why you embeded the VStack of the title and createdAt Texts for the ToDoItemView inside of a HStack?

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

    Brian -- can you also show how to do this using a ViewModel architecture?

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

    As I was building this by myself, I encountered a problem. With Core Data, everything works fine. But how can I add a WebRequest with the URL Session to this project?
    Maybe you could help me archieve this withhin the already existing "FetchedResults" and "Fetchrequest".
    Best regards

  • @jersey-dude
    @jersey-dude 5 лет назад

    In creating the ToDoItem.swift file, I get plenty of errors stating that it is a redeclaration of the class. I found that adding the data model to core data, it creates this class with this name. So I guess we dont need to do that? Only thing is, I can't create the extension. not sure why. If I comment out the class and just add the extension, I get the message that I am using an ambiguous use of fetchRequest().. UGH
    If I dont, however, use the same entity name, all seems OK..

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

    Question: Why is het unsafe to unwrap the title en createdAt when showing it in de section with ToDoItemView.
    Hope you understand what i mean.

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

    Thanks for the tutorial!

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

    hey ... random question ... how can you make a clone of notion or taskade.com ?

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

    Hi Brian, thanks for your amazing tutorials! I used your video(s) as a guide to set up a very basic watchOS 6 application with Core Data support. However, I ran into very weird issues, like I'm unable to set the managedObjectContext once at the ContentView level (inside ExtensionDelegate), and then use it later on in sub views (Context in environment is not connected to a persistent store coordinator).
    Would highly appreciate any advice. Thanks!

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

    Cool that can delete. But can’t mark as done (strike and another color)

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

    Very good, thanks a lot!

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

    great thanks you, how you think when all will start use swiftui?

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

      I will use it today. But I recommend to use it only if you don't need backwards compatibility and have fun fixing a lot of bugs and changes over the years. But useable is it right now (kind of you need to mix it with UIKit). If you don't want to use it today I think you should wait 1-2 years

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

    How to add a max length for a UITEXT FIELD in SWIFT UI (i mean in this course)?

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

    how do we use previews when using core data?? im baffled 🤪

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

    Cool as always! Thank you

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

    greatly appreciated 🙏 🙏

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

    Thanks for the great tutorial! :D

  • @Ryan-sr9zv
    @Ryan-sr9zv 4 года назад

    How does this fit the MVVM pattern?

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

    Your tutorials a very good and I really appreciate them however it's really annoying that sometimes I got to pause the video and zoom the page so I could see what you are writing or choosing, would be really awesome if could sometimes zoom when writing code or in general just make it a bit more zoomed like you. Thx anyway :)

  • @MarkGregoryJ
    @MarkGregoryJ 4 года назад +2

    When following along, at 5:15 when defining a new public class, users get an 'Invalid Redeclaration' error. You skipped all explanation of how and why we are avoiding a redeclaration here. Many other examples of shallow and useless explanations. The video description begins with "Learn how to..." For a user wanting an actual tutorial to understand and not just be shown, this video falls short.

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

    Thanks for this guide, can you insert one with the integration of a search bar to filter the data in Core Data?

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

      You will need UIViewRepresantable for that

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

      I would like to completely eliminate the dependencies on UiKit :(

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

      I try with: ForEach(users.filter { self.serchedText == "" ? true : $0.name.localizedCaseInsensitiveCompare(self.serchedText) }, id: \.self) { user in... but gives me an error

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

      @@sermedix Unfortunately there are some UIKit elements that one will have to use in a SwiftUI project, but I'm sure the SwiftUI team is working hared on bringing us into the future, where all things will be made with SwiftUI magic 🧙‍♂️

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

    The tutorial is wonderful! Very easy to follow. Thanks!

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

    Thank you very much 👍

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

    Thanks for your useful tutorial. Could you add some example how to use onMove handler with new Core Data feature?

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

      stackoverflow.com/questions/57426250/modifying-a-fetchrequest

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

      ​@@robertdesaegercto3043 I'd like to see code that changes the order of items.

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

    I'm new to coding and when follow your tutorial the app crashes when i try to delete an object. I went over it many times and get the same result. Maybe I'm missing something?

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

      Please provide the steps that let to the crash and the actual log of the crash from the console. If it's too long than you should try posting it on stackoverflow

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

    Hi Brian, great video by the way. I have a question. I am creating an app that can save passwords, but I don’t want to use Firebase. what it does it saves the passwords on the iPhone. Would Apple allow this?
    Thanks,
    Amez

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

      That seems like a horrible idea. Can't you use keychain?

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

      Ben Mitchell I dont want to use anything thats on the icloud or online

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

      Apple would not allow this unless it was encrypted. Even then, they probably still wouldn't let it in the App Store. Use it for personal use

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

      Ben Mitchell so basically what I have is an app that you need a password to enter to access a text doc to add your passwords

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

    I'm getting a "Failed to call designated initializer on NSManagedObject" warning.

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

    OOh, how do you do that foldy thing? Ive googled foldy thing and got nothing, confused the hell out of me when you did it!

    • @James-pj6cg
      @James-pj6cg 4 года назад

      Click on the editor menu and go to code folding, Or press "option + command + left arrow key to fold" and right arrow key to unfold

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

      James my guy! thanks buddy

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

    Can you do a tutorial on Bluetooth with SwiftUI?

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

    Does anybody know how to create a countdown app using swiftUI?

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

      It's pretty easy. Contact me to show you how.

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

      Rebeloper - Rebel Developer how would you like me to contact you?

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

    TextField("ааа", text: self.$newToDoItem)
    Type of expression is ambiguous without more context
    Any thoughts?

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

      CoreData in SwiftUI tutoríal : ruclips.net/video/X2qeZj0Xzrs/видео.html

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

    Nice tutorial, could you explain what the scene delegate file is for ?

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

    Video starts at 1:50

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

    Nice, but... please bump up the font or reduce the resolution.

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

    I'm sure if you redo this tutorial following your video you will discover errors in cutting the video because the code is missing

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

    19:39 how you did it?

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

      You need to enable it in preferences

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

      CoreData in SwiftUI tutoríal : ruclips.net/video/X2qeZj0Xzrs/видео.html

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

    Well it is basically not a tutorial.

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

    No apostrophe in To-Dos, shouldn't be "ToDo's"; however, "Whats Next" should be "What's Next" ;)

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

    🎊✌🏻️ 1st

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

    Dude you are just showing but not explaining what is what...

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

      CoreData in SwiftUI tutoríal : ruclips.net/video/X2qeZj0Xzrs/видео.html

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

    what is the difference between a view controller and a content view I am confused if I have to use a content view instead?

  • @jersey-dude
    @jersey-dude 5 лет назад

    Great job! Thank you