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:
@Modelclass 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.

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

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

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
Like to support my work?
Say hi
Related tags
Articles with related topics
Latest articles and tips



