Skip to content

SwiftUI

Previews are development-only code. A view that is only referenced from a preview isn’t used by your application, so by default Periphery does not treat that preview as a reference. A view referenced only from a #Preview macro is reported as unused. For types conforming to PreviewProvider, both the provider type and the view it exercises are reported as unused.

struct MyView: View { // 'MyView' is unused
var body: some View { Text("Hello") }
}
#Preview {
MyView()
}

If you’d rather keep previews and the views they reference, retain them with --retain-swiftui-previews.

Properties declared with @UIApplicationDelegateAdaptor or @NSApplicationDelegateAdaptor in your @main type are automatically retained, along with the delegate types they reference. No configuration is required.

Types conforming to LibraryContentProvider are automatically retained, as they’re referenced by Xcode’s library rather than by your code.