Skip to content

Matt54633/SWTools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

 

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!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages