In this document, you will find detailed information about the NSStringMask library. NSStringMask is a third-party library that provides a convenient way to apply masks to NSString objects, allowing for easy text formatting and validation.
Installation
To use NSStringMask in your project, follow these steps:
Using CocoaPods
- Add the following line to your Podfile:
- Run the command
pod install
. - Import the library into your project using:
pod 'NSStringMask'
import NSStringMask
Manual Installation
- Download the NSStringMask repository from the official GitHub page: https://github.com/your-repository.
- Drag and drop the
NSStringMask
folder into your Xcode project. - Make sure to check the option “Copy items if needed” and select your desired targets.
- Import the library into your project using:
import NSStringMask
Usage
NSStringMask provides various mask formats that can be applied to an NSString object. Here are some common examples:
Phone Number Mask
To format a phone number, use the following mask:
[myString maskString:@"(###) ###-####"];
This will transform the input string to the format: (123) 456-7890.
Credit Card Mask
To format a credit card number, use the following mask:
[myString maskString:@"####-####-####-####"];
The input string will be masked as: 1234-5678-9012-3456.
Date Mask
For formatting a date, use the mask:
[myString maskString:@"##/##/####"];
Your input will be masked in the format: 12/31/2022.
Additional Methods
NSStringMask provides additional methods for more control over the masking process:
Unmasking
To retrieve the original unmasked string, use the following method:
NSString *originalString = [myString originalString];
This will return the unmasked string without the formatting characters.
Validation
NSStringMask offers a convenient method to validate masked strings. Use the following method:
BOOL valid = [myString complete];
The complete method will return YES if all required characters are filled, otherwise it will return NO.
In conclusion, NSStringMask is a valuable library for text formatting and validation purposes. By applying masks to NSString objects, you can easily achieve consistent and desired formatting. This documentation provides an overview of the installation process, basic usage, and additional methods offered by the NSStringMask library.