SwiftData Indexes
SwiftData, introduced in iOS 17, initially lacked database indexing capabilities. iOS 18 rectified this omission, allowing for fetch indexes to improve database lookups. Core Data has long supported adding fetch indexes, which accelerate database lookups based on specific properties. In the Xcode Core Data Model Editor, you can add fetch indexes by selecting the entity and using the "Add Fetch Index" option. However, despite iOS 18 introducing support for fetch indexes in SwiftData, Xcode 16 still displays a warning that fetch indexes are not supported. To add SwiftData fetch indexes, use the #Index macro to specify the key path for each index. You can only use the #Index macro once for each model class, so all indexes must be listed in the single macro. Compound indexes, which are useful for sorting items with duplicate properties, can also be added. For more information, refer to the WWDC24 documentation on "What's new in SwiftData."