SWTools

1.0.7

Matt54633/SWTools

What's New

2024-05-19T12:47:39Z

 

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.

Installation

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

Usage

MacOS Detection

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
}

iPad Detection

To detect if the current device in use is an iPad, use the isOnIpad environment property:

@Environment(\.isOnIpad) var isOnIpad

if isOnIpad {
    // execute code
}

Safe Area Detection

To detect the safe area insets of a device, use the safeAreaInsets environment property:

@Environment(\.safeAreaInsets) var safeAreaInsets

if safeAreaInsets.bottom > 20 {
    // execute code
}

Haptic Feedback

To provide simple haptic feedback, use the hapticFeedback function:

Rectangle()
    .onTapGesture {
        hapticFeedback(.medium)
    }

Shake Detection

To detect a shake gesture simply add the .onShake modifier to a View:

Rectangle()
    .onShake {
        // execute code
    }

Other Tools

Calendar Extensions

- Number of Days Between Dates

Color Extensions

- Return RGBA Components
- Return HEX Code
- Return HSL Components
- Convert to Hex Code
- Convert to HSL

See the source code for further information!

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 19:28:00 GMT-0900 (Hawaii-Aleutian Daylight Time)