ipedro/swiftui-property-inspector
[PropertyInspector](https://ipedro.github.io/swiftui-property-inspector/documentation/propertyinspector/propertyinspector) is a SwiftUI component that provides a powerful and flexible way to inspect and interact with properties dynamically. It's designed for developers who want t
Features
- Dynamic Property Inspection: Intuitively inspect properties of any type within your SwiftUI views.
- Customizable UI: Easily customize icons, labels, and detail views for each property.
- Sorting Capability: Sort properties using custom criteria for better organization and accessibility.
- Search Functionality: Quickly find properties with a built-in search feature.
- Environment Customization: Adjust corner radius for the property highlight view using environment values.
Requirements
- iOS 15.0+
- Swift 5.7+
- Xcode 15.0+
Installation
Swift Package Manager
Add swiftui-property-inspector to your project by including it in your Package.swift file:
dependencies: [
.package(url: "https://github.com/ipedro/swiftui-property-inspector", .upToNextMajor(from: "1.0.0"))
]Then, import swiftui-property-inspector in your SwiftUI views to start using it.
Documentation
The full documentation for swiftui-property-inspector can be found here.
Usage
Here's a simple example of using PropertyInspector in your SwiftUI views:
[SwiftUI PropertyInspector plain list style example]
import PropertyInspector
import SwiftUI
var body: some View {
PropertyInspector(listStyle: .plain) {
VStack(content: {
InspectableText(content: "Placeholder Text")
InspectableButton(style: .bordered)
})
.propertyInspectorRowLabel(for: Int.self, label: { data in
Text("Tap count: \(data)")
})
.propertyInspectorRowIcon(for: Int.self, icon: { data in
Image(systemName: "\(data).circle.fill")
})
.propertyInspectorRowIcon(for: String.self, icon: { _ in
Image(systemName: "text.quote")
})
.propertyInspectorRowIcon(for: (any PrimitiveButtonStyle).self, icon: { _ in
Image(systemName: "button.vertical.right.press.fill")
})
}
}struct InspectableText<S: StringProtocol>: View {
var content: S
var body: some View {
Text(content).inspectProperty(content)
}
}struct InspectableButton<S: PrimitiveButtonStyle>: View {
var style: S
@State private var tapCount = 0
var body: some View {
Button("Tap Me") {
tapCount += 1
}
// inspecting multiple values with a single function call links their highlight behavior.
.inspectProperty(style, tapCount)
.buttonStyle(style)
}
}Disabling Inspection
To disable the property inspection:
var body: some View {
MyView().propertyInspectorHidden()
}Contributing
We welcome contributions! If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.
License
The swiftui-property-inspector package is released under the MIT License. See LICENSE for details.
Package Metadata
Repository: ipedro/swiftui-property-inspector
Default branch: main
README: README.md