LibraryContentProvider protocol in Xcode is a way for adding custom views and view modifiers to the Xcode library, which enables drag and dropping them to the SwiftUI preview. Xcode automatically looks for types implementing the protocol and then adds items to the library. It takes so little code that it makes sense to do it if you are using the library for building views.
As an example, we’ll add a custom SwiftUI view SubtitledButton to the library.
The only thing we need to do is creating a new type which conforms to LibraryContentProvider and then returning the button as a LibraryItem.
After adding the new type, Xcode updates the library automatically.
If this was helpful, please let me know on Mastodon@toomasvahter or Twitter @toomasvahter. Feel free to subscribe to RSS feed. Thank you for reading.