Thank you for your lessions in that series. Your language and explanations are clear and understandable even for me as a non english native speaker. I‘m espacially thankfull for your report on bugs and the solutions that you present, not very often found in TH-cam tutorials.
Definitely amazing series 🎉 … thank you so very much for that ❤️ for your efforts and fantastic explanation 👌. Happy New Year 🥳 Stewart ! For You and Family 🎉🎉🎉 All the best!
Great series. Think I'm gonna hold of from SwiftData for now and continue on the CoreData + MVVM path. Storing and syncing Images works great already. I wouldn't know where to put al my logic if I start using SwiftData. I like MVVM for that, don't know yet what best practise there would be with SwiftData (MV pattern?) . Perhaps we'll see a series from you on that in the future!
This series was a wonderful teaching tool for how to get started with SwiftData. Unfortunately on iOS 18 there seem to be a couple of more bugs. -the first has to do with when typing into the synopsis panel and displaying the on device keyboard on a smaller phone like the iPhone 15, the view gets messed up and makes it so you are unable to see what you are typing while also messing with a few other things like the rating and the title. -the second is when deleting genres it no longer functions the way it did in the video. it deletes the genre from the genre list and for the book you were editing the genre list in, but it doesn’t delete them for any other book that is attached to them. -and then finally I sometimes get a bug when I add a genre that the color does not show up it just shows the name but there is no way to tell if you have toggled it on or off. I have been trying to solve these on my own but I have not come up with anything. in apple’s developer videos I can not find any changes that have been made that would cause these to happen. thanks again for the course it has been super helpful.
I fixed the deletion of a genre by doing a Query for the books @Query var books: [Book] in GenresView Then I enclosed the "if let bookGenres = book.genres,..." in a " for book in books { } " the book is now referring to each from the query instead of the one bound book finally, after the "context.delete(genres[index])", i saved the context in a try/catch. I saved my data after all creations or updates as it seemed to be needed. Hope this helps Judy
On an app I'm currently working on the `@Attribute(.externalStorage)` is not working as expected, as I see the whole blobs (50KB+) being stored internally (they show as BLOBs, not images, but still I think those are large files regardless). The .default_SUPPORT folder is also not storing the images created from this data; I see all the large blobs in the persisted table. Not sure what's going on. Do you think that SwiftData possibly only respects the `.externalStorage` if the Data you're trying to save is larger (like 1MB+)? I saw a blog from Paul Hudson that mentioned something along these lines, but there's no in-depth discussion about it, just a brief mention of this issue.
Hey, nice video ! I got a question - is it possible to pick an Image but with fixed aspect ratio with the Photospicker ? So lets say I am choosing an Image in my library, but then I get like a frame(fixed ratio like 2:1) on that Image where I can decide which part with that ratio I want to load. Or do i have to load it like so and make it resizable and scale it then ?
You cannot do it directly from the photopicker but you could load the image onto a canvas and then draw a rectangle on it for the frame and then use UIGraphicsImageRenderer to grab the area under the rectangle.
Great series! How would you go about resizing the image so that the data would take up less storage (other than jpg compression)? It seems like an area that you would never need the original full size image and having the image stored at a couple hundred kb rather than a few mb would be ideal?
Here is a gist of two extensions that I include in most of my projects that allow me to scale images. gist.github.com/StewartLynch/683d19ed0cd9fb600607da0b6f99aa49
I tried out your code and it’s a life saver. Right now I have the image data being stored in my documents directory, but I plan on switching over to storing it in swift data like you’ve shown here some I’m already using Swift data to store the url. Great video
@@StewartLynch Wow! Great minds think alike 😅. I said that because I've just made a little project using something like that. Can't wait to see what you have for us!
Super series! I like your teaching style. thanks for all your efforts. I am new to swiftUI and was wondering if you had any videos on using TabViews and SwiftData, specifically how to pass info from one screen to another, such as, tracking a character Model showing a List of characters on one screen then moving to another tab to enter data for the character/Item selected on the first screen into another Model. Would appreciate being pointed in the correct direction.
TabViews are not really meant for that Ricky. What you describe is either a NavigationStack or a modal sheet presentation. I have lots of videos on those topics. Send me an email (Links in my profile) if you want to discuss this further.
Thank you Stewart for an interesting video. Also I wanted to ask if you or someone have come across such SwiftData/iCloud app issues: 1. In Settings > iCloud > Manage Account Storage: clicking on the app to delete its iCloud data - does not open the next page - it only shows a spinner and that's it. Maybe I missed something in the code or setup to enable it? 2. Images with some data keep disappearing after app is restarted, sometimes they re-appear after awhile (might be related to connection) - but I would expect it to cache locally instead of removing/re-adding them. Any ideas would be really appreciated. Thank you very much in advance!
This was wonderful. I'm trying to store multiple images & am wondering how you'd handle a situation where you want the images to be stored externally (@Attribute(.externalStorage)) and also want deletions to cascade (@Relationship(deleteRule: .cascade)). Apparently putting both decorators above an array of data gives an error that they can't be composed. Thanks again for your work. It's great!
@@StewartLynch I'll have to explore this more. I'm finding that if I have a model with a single image, then save one image at a time to the model & query all saved values as an array of that model, I get the hidden .default_SUPPORT folder, BUT if I add a property to a SwiftData model that's an array of images and get this working, even with the .externalStorage - say something like this: @Attribute(.externalStorage) var imageArray: [Data?] if I look at the simulator's Application Support directory I don't see the hidden folder, so it's unclear if arrays of Data like this are even using .externalStorage. I may be completely missing something, but this is what I'm seeing right now. Will let you know if I discover more.
I just realized that I am doing this in my new app. What I do is create a new model for the image with a single property that is data. then in my model I have an array of SitePhoto with a cascade delete. It all seems to work for me. Follow up with a DM on Mastodon or X if you want to discus more. @Model class SitePhoto { @Attribute(.externalStorage) var data: Data? var image: UIImage? { if let data { return UIImage(data: data) } else { return nil } } init(data: Data) { self.data = data } }
I don’t think you would want to save video files to a SQLLite database. I would just store the videos on device with an ID and then reference them in the database.
@@StewartLynch Great point about not wanting to save the video in the database, but that does bring up an issue regarding CloudKit. If you were to store the videos locally in your apps .documentdirectory, what would be the way to have those files synced with CloudKit. I did a few searches and wasn't able to find any information on syncing a app folder.
@@StewartLynch thanks for the reply Stewart. I guess to make this less theoretical, I’m working on an app that specifically needs to be able to have offline video capabilities. It’s great that the swift data that holds all the urls and images can be directly stored in CloudKit, but if you absolutely need to have the videos stored locally in your apps documents directory, is there any way you know of to tell CloudKit to include an entire folder? I realize that syncing may take a few minutes, but I’m not sure hot to go about doing that? Or would you go to something else for that kind of syncing? Something like firebase?
@@joshgoble Why not try saving the video file as shown for saving an image, as the video file is large it will be placed in external storage as Stuart shows. Then see if cloudKit can handle the sync. Maybe the CloudKit docs describe the limits on file sizes it can handle. Experimentation leads to knowledge.
Thank you for your lessions in that series. Your language and explanations are clear and understandable even for me as a non english native speaker. I‘m espacially thankfull for your report on bugs and the solutions that you present, not very often found in TH-cam tutorials.
You're very welcome!
Merry Christmas !!
And to you as well.
this was a masterful series btw. Your work is very much appreciated Stewart ❤
Thank you
Thank you for another great video!
Definitely amazing series 🎉 … thank you so very much for that ❤️ for your efforts and fantastic explanation 👌. Happy New Year 🥳 Stewart ! For You and Family 🎉🎉🎉 All the best!
Great series. Think I'm gonna hold of from SwiftData for now and continue on the CoreData + MVVM path. Storing and syncing Images works great already. I wouldn't know where to put al my logic if I start using SwiftData. I like MVVM for that, don't know yet what best practise there would be with SwiftData (MV pattern?) . Perhaps we'll see a series from you on that in the future!
This series was a wonderful teaching tool for how to get started with SwiftData. Unfortunately on iOS 18 there seem to be a couple of more bugs.
-the first has to do with when typing into the synopsis panel and displaying the on device keyboard on a smaller phone like the iPhone 15, the view gets messed up and makes it so you are unable to see what you are typing while also messing with a few other things like the rating and the title.
-the second is when deleting genres it no longer functions the way it did in the video. it deletes the genre from the genre list and for the book you were editing the genre list in, but it doesn’t delete them for any other book that is attached to them.
-and then finally I sometimes get a bug when I add a genre that the color does not show up it just shows the name but there is no way to tell if you have toggled it on or off.
I have been trying to solve these on my own but I have not come up with anything. in apple’s developer videos I can not find any changes that have been made that would cause these to happen. thanks again for the course it has been super helpful.
I fixed the deletion of a genre by doing a Query for the books @Query var books: [Book] in GenresView
Then I enclosed the "if let bookGenres = book.genres,..." in a " for book in books { } "
the book is now referring to each from the query instead of the one bound book
finally, after the "context.delete(genres[index])", i saved the context in a try/catch.
I saved my data after all creations or updates as it seemed to be needed.
Hope this helps Judy
Thanks! Keep up the great content!
Thank you so much.
On an app I'm currently working on the `@Attribute(.externalStorage)` is not working as expected, as I see the whole blobs (50KB+) being stored internally (they show as BLOBs, not images, but still I think those are large files regardless). The .default_SUPPORT folder is also not storing the images created from this data; I see all the large blobs in the persisted table. Not sure what's going on. Do you think that SwiftData possibly only respects the `.externalStorage` if the Data you're trying to save is larger (like 1MB+)? I saw a blog from Paul Hudson that mentioned something along these lines, but there's no in-depth discussion about it, just a brief mention of this issue.
That may very well be the case. I think I read that somewhere too.
Hey, nice video !
I got a question - is it possible to pick an Image but with fixed aspect ratio with the Photospicker ?
So lets say I am choosing an Image in my library, but then I get like a frame(fixed ratio like 2:1) on that Image where I can decide which part with that ratio I want to load.
Or do i have to load it like so and make it resizable and scale it then ?
I have not gone down that path myself. I do not think it is natively possible
You cannot do it directly from the photopicker but you could load the image onto a canvas and then draw a rectangle on it for the frame and then use UIGraphicsImageRenderer to grab the area under the rectangle.
Great series! How would you go about resizing the image so that the data would take up less storage (other than jpg compression)? It seems like an area that you would never need the original full size image and having the image stored at a couple hundred kb rather than a few mb would be ideal?
Here is a gist of two extensions that I include in most of my projects that allow me to scale images. gist.github.com/StewartLynch/683d19ed0cd9fb600607da0b6f99aa49
@@StewartLynch thanks!
I tried out your code and it’s a life saver. Right now I have the image data being stored in my documents directory, but I plan on switching over to storing it in swift data like you’ve shown here some I’m already using Swift data to store the url. Great video
Hi Stewart , thanks for you video , i have question here, if i want to fetch the image in the list of listview ,what should i do ?
What do you mean by fetch the image? I don’t understand your question
Thank you Stewart! I wonder if there is a way to pick photos from the camera just like that
Funny you should say that. I am working on a video on that topic. Won’t be out for. month or so though.
@@StewartLynch Wow! Great minds think alike 😅. I said that because I've just made a little project using something like that. Can't wait to see what you have for us!
Super series! I like your teaching style. thanks for all your efforts. I am new to swiftUI and was wondering if you had any videos on using TabViews and SwiftData, specifically how to pass info from one screen to another, such as, tracking a character Model showing a List of characters on one screen then moving to another tab to enter data for the character/Item selected on the first screen into another Model. Would appreciate being pointed in the correct direction.
TabViews are not really meant for that Ricky. What you describe is either a NavigationStack or a modal sheet presentation. I have lots of videos on those topics. Send me an email (Links in my profile) if you want to discuss this further.
Thank you Stewart for an interesting video. Also I wanted to ask if you or someone have come across such SwiftData/iCloud app issues: 1. In Settings > iCloud > Manage Account Storage: clicking on the app to delete its iCloud data - does not open the next page - it only shows a spinner and that's it. Maybe I missed something in the code or setup to enable it? 2. Images with some data keep disappearing after app is restarted, sometimes they re-appear after awhile (might be related to connection) - but I would expect it to cache locally instead of removing/re-adding them. Any ideas would be really appreciated. Thank you very much in advance!
This was wonderful. I'm trying to store multiple images & am wondering how you'd handle a situation where you want the images to be stored externally (@Attribute(.externalStorage)) and also want deletions to cascade (@Relationship(deleteRule: .cascade)). Apparently putting both decorators above an array of data gives an error that they can't be composed. Thanks again for your work. It's great!
Good question John. I have not explored that yet
@@StewartLynch I'll have to explore this more. I'm finding that if I have a model with a single image, then save one image at a time to the model & query all saved values as an array of that model, I get the hidden .default_SUPPORT folder, BUT if I add a property to a SwiftData model that's an array of images and get this working, even with the .externalStorage - say something like this:
@Attribute(.externalStorage) var imageArray: [Data?]
if I look at the simulator's Application Support directory I don't see the hidden folder, so it's unclear if arrays of Data like this are even using .externalStorage. I may be completely missing something, but this is what I'm seeing right now. Will let you know if I discover more.
I just realized that I am doing this in my new app. What I do is create a new model for the image with a single property that is data. then in my model I have an array of SitePhoto with a cascade delete. It all seems to work for me. Follow up with a DM on Mastodon or X if you want to discus more.
@Model
class SitePhoto {
@Attribute(.externalStorage)
var data: Data?
var image: UIImage? {
if let data {
return UIImage(data: data)
} else {
return nil
}
}
init(data: Data) {
self.data = data
}
}
another way to solve the Preview problem while leaving it in the Preview Contents folder is to add `#if DEBUG` directives on all previews
Thanks for sharing
Thanks!
Thank you
in my project i can add and save Video files in SwiftData
I don’t think you would want to save video files to a SQLLite database. I would just store the videos on device with an ID and then reference them in the database.
@@StewartLynch Great point about not wanting to save the video in the database, but that does bring up an issue regarding CloudKit. If you were to store the videos locally in your apps .documentdirectory, what would be the way to have those files synced with CloudKit. I did a few searches and wasn't able to find any information on syncing a app folder.
@joshgoble you would be better storing the video somewhere where it can be streamed and then just store the link
@@StewartLynch thanks for the reply Stewart. I guess to make this less theoretical, I’m working on an app that specifically needs to be able to have offline video capabilities. It’s great that the swift data that holds all the urls and images can be directly stored in CloudKit, but if you absolutely need to have the videos stored locally in your apps documents directory, is there any way you know of to tell CloudKit to include an entire folder? I realize that syncing may take a few minutes, but I’m not sure hot to go about doing that? Or would you go to something else for that kind of syncing? Something like firebase?
@@joshgoble Why not try saving the video file as shown for saving an image, as the video file is large it will be placed in external storage as Stuart shows. Then see if cloudKit can handle the sync. Maybe the CloudKit docs describe the limits on file sizes it can handle. Experimentation leads to knowledge.
Thanks!
Thank you so much Andrew