SWTools is versatile Swift Package for use with SwiftUI, allowing you to detect shake gestures and safe area insets, extend types and more!
This package is compatible with iOS, MacOS and VisionOS.
SWTools uses Swift Package Manager. Therefore, add https://github.com/matt54633/SWTools as a package dependency to your project.
Once installed, import SWTools where required using:
import SWTools
If using the MacOS(Designed for iPad)
destination, running specific code for MacOS can be challenging. To simplify this process, use the isOnMac
environment property:
@Environment(\.isOnMac) var isOnMac
if isOnMac {
// execute code
}
To detect if the current device in use is an iPad, use the isOnIpad
environment property:
@Environment(\.isOnIpad) var isOnIpad
if isOnIpad {
// execute code
}
To detect the safe area insets of a device, use the safeAreaInsets
environment property:
@Environment(\.safeAreaInsets) var safeAreaInsets
if safeAreaInsets.bottom > 20 {
// execute code
}
To provide simple haptic feedback, use the hapticFeedback function:
Rectangle()
.onTapGesture {
hapticFeedback(.medium)
}
To detect a shake gesture simply add the .onShake
modifier to a View:
Rectangle()
.onShake {
// execute code
}
- Number of Days Between Dates
- Return RGBA Components
- Return HEX Code
- Return HSL Components
- Convert to Hex Code
- Convert to HSL
See the source code for further information!