I’m trying to add my own SwiftUI view to the Xcode library in Xcode 16.
However, the view does not appear in the library.
Does anybody have a hint, what could be missing?
Searching for the topic brings up a couple of blog posts with similar code, however, neither works for me. Tried Xcode 16.0, 16.1, 15.4.
- Apple’s WWDC Video on the topic: https://developer.apple.com/videos/play/wwdc2020/10649/
- Documentation: https://developer.apple.com/documentation/developertoolssupport/librarycontentprovider
My test code:
import DeveloperToolsSupport
import SwiftUI
protocol LibraryContentProvider {
@LibraryContentBuilder
var views: [LibraryItem] { get }
// Do that later...
/*
@LibraryContentBuilder
func modifiers(base: Custom1View) -> [LibraryItem] {
[]
}
*/
}
struct CustomView: View {
let title: String
let message: String
var body: some View {
VStack {
Text(title)
.bold()
Text(message)
}
.padding(8)
.border(.gray, width: 2)
}
}
struct MyLibraryContent: LibraryContentProvider {
@LibraryContentBuilder
var views: [LibraryItem] {
LibraryItem(
CustomView(title: "title1", message: "message1"),
title: "Custom Title"
)
}
}