SWTools

1.0.5

Matt54633/SWTools

What's New

2024-04-29T20:43:59Z
  • Added iPad Detection

 

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

Shake Detection

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

Rectangle()
    .onShake {
        // execute code
    }

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
}

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: Thu May 02 2024 14:05:57 GMT-0900 (Hawaii-Aleutian Daylight Time)