After working on a few different apps, I found myself recycling some of the same extensions and SwiftUI Views, so I decided to consolidate all of my most commonly used code into a Swift Package called SwiftPlus! I've linked it below.
SwiftPlus includes extensions for Date String formatting, various View extensions for making working with SwiftUI even easier, and more. Some of the code in SwiftPlus was taken from various posts across Stack Overflow. When this is the case, the URL to whatever post the code came from is included in the applicable code's documentation.
In this video, I cover a very common use case for the .isReallyEmpty String extension included with SwiftPlus: form validation. When prompting a user to sign up for an app, for example, it's common to verify that the user has filled in all the required fields before allowing them to create their account.
To do this in Swift, you might be inclined to simply write a guard statement combined with the .isEmpty computed property included with Swift, but it's not that easy. The problem with this approach is that the .isEmpty property will return false even if all a String contains is blank space (i.e. the user pressed the space bar but didn't enter any letters, numbers, or special characters) 😅
Any easy solution for this issue is the .isReallyEmpty String extension included with SwiftPlus. That's because, before it returns a value, .isReallyEmpty will evaluate a version of a String that has all of its blank space and line breaks removed. This is perfect, as it means that a user can no longer bypass a required field by entering blank space 🤓
🙋♂️ Have you ever made a Swift Package to consolidate code that you commonly use across different projects? If so, tell me about it down in the comments! 💬
Get SwiftPlus here: https://github.com/julianworden/Swift...
Check out my website here: https://www.julianmichaeltechnologies...
Follow my other socials here:
Instagram: / jmichaeltech
TikTok: / jmichaeltechnologies
Facebook: https://www.facebook.com/jmichaeltech...
Twitter: / jmichaeltech
#shorts