Skip to content

Commit a338541

Browse files
committed
WIP
1 parent 6d9e829 commit a338541

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Install
6262
```swift
6363
let package = Package(
6464
dependencies: [
65-
.package(url: "https://github.com/siteline/swiftui-introspect", from: "1.0.0"),
65+
.package(url: "https://github.com/siteline/swiftui-introspect", from: "26.0.0"),
6666
],
6767
targets: [
6868
.target(name: <#Target Name#>, dependencies: [
@@ -75,7 +75,7 @@ let package = Package(
7575
### CocoaPods
7676

7777
```ruby
78-
pod 'SwiftUIIntrospect', '~> 1.0'
78+
pod 'SwiftUIIntrospect', '~> 26.0.0'
7979
```
8080

8181
Introspection
@@ -143,6 +143,18 @@ SwiftUI | Affected Frameworks | Why
143143
Text | UIKit, AppKit | Not a UILabel / NSLabel
144144
Image | UIKit, AppKit | Not a UIImageView / NSImageView
145145
Button | UIKit | Not a UIButton
146+
Link | UIKit, AppKit | Not a UIButton / NSButton
147+
NavigationLink | UIKit | Not a UIButton
148+
GroupBox | AppKit | No underlying view
149+
Menu | UIKit, AppKit | No underlying view
150+
Spacer | UIKit, AppKit | No underlying view
151+
Divider | UIKit, AppKit | No underlying view
152+
HStack, VStack, ZStack | UIKit, AppKit | No underlying view
153+
LazyVStack, LazyHStack, LazyVGrid, LazyHGrid | UIKit, AppKit | No underlying view
154+
Color | UIKit, AppKit | No underlying view
155+
ForEach | UIKit, AppKit | No underlying view
156+
GeometryReader | UIKit, AppKit | No underlying view
157+
Chart | UIKit, AppKit | No underlying view
146158

147159
Examples
148160
--------
@@ -154,12 +166,10 @@ List {
154166
Text("Item")
155167
}
156168
.introspect(.list, on: .iOS(.v13, .v14, .v15)) { tableView in
157-
tableView.backgroundView = UIView()
158-
tableView.backgroundColor = .cyan
169+
tableView.bounces = false
159170
}
160171
.introspect(.list, on: .iOS(.v16, .v17, .v18, .v26)) { collectionView in
161-
collectionView.backgroundView = UIView()
162-
collectionView.subviews.dropFirst(1).first?.backgroundColor = .cyan
172+
collectionView.bounces = false
163173
}
164174
```
165175

@@ -170,7 +180,7 @@ ScrollView {
170180
Text("Item")
171181
}
172182
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26)) { scrollView in
173-
scrollView.backgroundColor = .red
183+
scrollView.bounces = false
174184
}
175185
```
176186

@@ -195,6 +205,18 @@ TextField("Text Field", text: <#Binding<String>#>)
195205
}
196206
```
197207

208+
General Guidelines
209+
------------------
210+
211+
Here are some guidelines to keep in mind when using SwiftUI Introspect:
212+
213+
- **Use sparingly**: Introspection should be a last resort when you need to access underlying UIKit/AppKit components that SwiftUI does not expose. Overusing it can lead to fragile code that may break with future SwiftUI updates. As Apple introduces new modifiers to SwiftUI, consider replacing introspection with native SwiftUI solutions.
214+
- **Test on all target OS versions**: Since SwiftUI Introspect relies on the underlying view hierarchy, it's crucial to test your app on all the OS versions you intend to support. Different OS versions may have different underlying implementations, which can affect introspection.
215+
- **Do not modify state directly**: Avoid changing SwiftUI state directly from within the introspection closure. If you need to update state, enclose it within a `DispatchQueue.main.async` block to ensure it happens within safe SwiftUI update cycles.
216+
- **Do not assume idempotency**: The introspection closure may be called multiple times during the view's lifecycle, such as during view updates or re-renders. Ensure that your customization code can handle being executed multiple times without causing unintended side effects.
217+
- **Avoid retain cycles**: Be cautious about capturing `self` or other strong references within the introspection closure, as this can lead to memory leaks. Use `[weak self]` or `[unowned self]` capture lists as appropriate.
218+
- **Use the correct scope**: By default, the `.introspect` modifier acts on its receiver. If you need to introspect an ancestor view, make sure to set the `scope` parameter to `.ancestor`. In general, you won't need to worry about this as each view type has sensible, predictable scope defaults.
219+
198220
Advanced usage
199221
--------------
200222

0 commit comments

Comments
 (0)