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.
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
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
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:
- Find the helper that matches your use case.
- Copy the file or relevant extension into your app target.
- Rename, refactor, or modernize it to match your codebase and deployment target.
UIView_AutoLayout_Extension.swift: concise layout helpers for anchoring and filling viewsUIViewController_Keyboard_Extension.swift: keyboard observers, tap-to-dismiss, and simple alert supportApplyPatternOnNumbers.swift: number-string masking for formatted displayRegEx_Validation.swift: basic string validation helpersFeedbackSupport.swift: haptic and vibration feedback helpersTopViewController.swift: utility for retrieving the visible top controller
- 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.
No license file is currently included in this repository. Add one if you want to make reuse terms explicit on GitHub.