Logo for tanaschita.com

How to store images in SwiftData

Learn how to efficiently store larger amounts of data in SwiftData.

updated on 13 Jul 2026 · 1 min read

SwiftData allows us to store images by using the Data type, for example:

@Model
class Recipe {
var imageData: Data
}

When working with larger or many images, it might be a good idea to separate them from the model storage and store them in an external file. For that, SwiftData provides the .externalStorage attribute:

@Attribute(.externalStorage)
var imageData: Data?

With that in place, we tell SwiftData to store the image data in external storage managed by SwiftData, which may lead to improved performance when working with larger amounts of data.

Sponsorship logo
Preparing for a technical iOS job interview
Preparing for a technical iOS Job Interview with over 300 questions & answers. Covering Swift & Objective-C, SwiftUI & UIKit, Combine, HTTP Networking, iOS File System, Core Data, Concurrency with async/await, Security, Automated Testing, Dependency Management, AI & Machine Learning and more.
LEARN MORE
Sponsorship logo
Architecture & Design Patterns for iOS
This book is a practical guide to essential architectural principles and design patterns for iOS development. It covers strategies for building maintainable apps with Swift and SwiftUI, including dependency injection, navigation, common patterns, and modularization.
LEARN MORE
Sponsorship logo
Become a sponsor of tanaschita.com
By publishing an article on different iOS topics every week, tanaschita.com is constantly growing in the developer community and may provide a great audience for you as a sponsor.
CLICK TO LEARN MORE

Newsletter

Image of a reading marmot
Subscribe

Like to support my work?

Say hi

Related tags

Articles with related topics

swiftdata

persistence

swiftui

swift

ios

How to get a SwiftData model container and context in SwiftUI

Learn how to setup a SwiftData container and context directly in SwiftUI.

13 Jul 2026 · 4 min read

Latest articles and tips

© 2026 tanaschita.com

Privacy policy

Impressum