Skip to content

Michaelcraun/useful-swift

Repository files navigation

useful-swift

useful-swift is a personal collection of reusable Swift and UIKit snippets for common app-development tasks. It focuses on practical, copy-pasteable helpers for validation, formatting, layout, keyboard handling, haptics, colors, environment detection, and small workflow notes.

What's In This Repo

The repository currently includes snippets for:

  • string validation for email, phone numbers, and URLs
  • formatting numeric strings like phone numbers, ZIP codes, and SSNs
  • converting hex color strings to UIColor
  • simplified Auto Layout anchoring helpers for UIView
  • keyboard-handling helpers for UIViewController
  • haptic and vibration feedback utilities
  • finding the top-most presented view controller
  • truncating long strings
  • detecting development, testing, and production environments
  • Swift documentation comment examples
  • a note on bundling Swift Package resources in tests

Who This Is For

This repo is useful if you:

  • keep a personal library of proven Swift snippets
  • want quick UIKit helpers without pulling in a full dependency
  • need reference implementations for common app utilities

How To Use It

This is not structured as a packaged framework. Each file is intended to be referenced, adapted, or copied into your own project as needed.

Typical workflow:

  1. Find the helper that matches your use case.
  2. Copy the file or relevant extension into your app target.
  3. Rename, refactor, or modernize it to match your codebase and deployment target.

File Highlights

  • UIView_AutoLayout_Extension.swift: concise layout helpers for anchoring and filling views
  • UIViewController_Keyboard_Extension.swift: keyboard observers, tap-to-dismiss, and simple alert support
  • ApplyPatternOnNumbers.swift: number-string masking for formatted display
  • RegEx_Validation.swift: basic string validation helpers
  • FeedbackSupport.swift: haptic and vibration feedback helpers
  • TopViewController.swift: utility for retrieving the visible top controller

Notes

  • Most snippets are UIKit-oriented.
  • Some files are best treated as reference snippets and may need small fixes or modernization before dropping directly into production.
  • The included markdown note on package test resources is documentation rather than source code.

License

No license file is currently included in this repository. Add one if you want to make reuse terms explicit on GitHub.

About

Reusable Swift and UIKit utility snippets for validation, formatting, layout, keyboard handling, haptics, and other common app tasks.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages