Celebrating 200 Daily Coding Tips 🎉 all tutorials will be free to all this week!
Introspect gives you a way of accessing the UIKit type that a SwiftUI type is based on.
This is done through a number of modifiers that specify the kind of view that they are introspecting, such as introspectSlider
, and come with a UIKit control like UISlider
inside that closure. I’ve tried to include most of them here, but I’ve excluded things like introspectViewController
or introspectNavigationController
because they would end up being too complicated to show here.
Before getting started, you will need to use File > New Packages… to add a Swift package to your project.
Paste the URL below in the search box in the top right, and add Introspect to your project.
https://github.com/siteline/SwiftUI-Introspect.git
Now you can import Introspect
in any of your SwiftUI view files, and you’ll be able to access new View
modifiers.
In my examples I’ve tried to modify properties that don’t exist in SwiftUI.
There could be some duplication here, but the important thing is knowing that the value passed into the closure is a UIKit view. Simply adding a dot to the end of whatever you call the closure parameter will give you access to the completions. There are many properties and functions on each of these that you don’t normally have access to.
Try modifying them and see what you can do!
This is what it should look like: