A set of very small categories for NSString, NSMutableString, NSArray, and
NSDictionary that add a few sorely lacking features (isEmpty and containsKey:
methods, for instance).
Most of the methods are relatively self-explanatory, but this should clear things up for those of slightly greater ambiguity.
You can include MPTidbits in your project by simply copying all five source files into your project, and then importing the global header file in any file in which you want to use an MPTidbits method:
#import "MPTidbits.h"
These functions can be found in MPFunctions.h.
-
NSString *MPHexStringFromBytes(void *bytes, NSUInteger len)Returns a hexadecimal
NSStringrepresentation of the data referenced bybytes.lenshould be the length of the data (the number of bytes).
These methods can be found in NSString+MPTidbits.h.
-
- (BOOL)isEmptyReturns
YESonly if the receiver is either empty (no characters), or contains only whitespace characters. -
- (BOOL)isEmptyIgnoringWhitespace:(BOOL)ignoreWhitespaceIf
ignoreWhitespaceisYES, returnsYESonly if the receiver is either empty (no characters), or contains only whitespace characters. IfignoreWhitespaceisNO, returnsYESonly if the receiver is empty (no characters) -- it does not ignore whitespace characters. -
- (NSString *)stringByTrimmingWhitespaceReturns an
NSStringobject identical to the receiver except that any leading or trailing whitespace characters (the characters in the set returned byNSCharacterSet's+whitespaceCharacterSet) will be stripped. -
- (NSString *)MD5HashReturns an
NSStringobject that contains a 32-character hexadecimal representation of the receiver's MD5 hash. This method uses the functions of Foundation'sCommonCryptolibrary, which means that your project does not have to link against an outside library (eg, OpenSSL). -
- (NSString *)SHA1HashReturns an
NSStringobject that contains a 40-character hexadecimal representation of the receiver's SHA-1 hash. This method uses the functions of Foundation'sCommonCryptolibrary, which means that your project does not have to link against an outside library (eg, OpenSSL).
These methods can be found in NSString+MPTidbits.h.
-
- (void)trimCharactersInSet:(NSCharacterSet *)aCharacterSetStrips leading and trailing characters from the receiver that belong to
aCharacterSet. In contrast toNSString's-stringByTrimmingCharactersInSet:, this method operates on the receiver in place. -
- (void)trimWhitespaceStrips leading and trailing whitespace characters (the characters in the set returned by
NSCharacterSet's+whitespaceCharacterSet) from the receiver. In contrast to the above-stringByTrimmingWhitespace, this method operates on the receiver in place.
These methods can be found in NSCollections+MPTidbits.h.
-
- (BOOL)isEmptyReturns
YESonly if the receiver contains no objects: the equivalent of([receiver count] == 0).
These methods can be found in NSCollections+MPTidbits.h.
-
- (BOOL)isEmptyReturns
YESonly if the receiver contains no objects: the equivalent of([receiver count] == 0). -
- (BOOL)containsKey:(NSString *)aKeyReturns
YESonly if the keyaKeyhas an associated object in the receiver. -
- (BOOL)containsKey:(NSString *)aKey allowEmptyValue:(BOOL)allowEmptyIf
allowEmptyisYES, returnsYESonly if the keyaKeyhas an associated object in the receiver. IfallowEmptyisNO, returnsYESonly if the keyaKeyhas an associated object in the receiver, and that object is neither theNSNullobject, nor does it returnYESto anisEmptymessage (if the object responds to it). This method is useful if you want to quickly check if a key both exists, and is not an empty string, for example.
MPTidbits is licensed under the MIT license, excerpted below.
Copyright (C) 2008 - 09 Matt Patenaude.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.