As a Java native, I am always a little worried when doing Objective-C because of memory leaks and pointers flying at my head...All comments are welcome on the Category below.  The Category functions are correct.GitHub#import NSString+r47.h@implementation NSString (r47)-(NSString *) r47String{    const char *_string = [self cStringUsingEncoding:NSASCIIStringEncoding];    int stringLength = [self length];    char newString[stringLength+1];    int x;    for( x=0; x<stringLength; x++ )    {        unsigned int aCharacter = _string[x];        if( 0x20 < aCharacter && aCharacter < 0x7F ) // from ! to ~            newString[x] = (((aCharacter - 0x21) + 0x2F) % 0x5E) + 0x21;        else  // Not an r47 character            newString[x] = aCharacter;    }    newString[x] = '\0';    NSString *rotString = [NSString stringWithCString:newString encoding:NSASCIIStringEncoding];    DLog(@%@ = %@,self,rotString);    return rotString ;}@end
Rot47 an NSString Category
strings;objective c;ios;caesar cipher;category
This bit looks just a bit suspect:int stringLength = [self length];char newString[stringLength+1];You're using the NSString length property to size the C char array allocation. This assumes that the string's length value (which reflects number of composed unicode characters) will always be equal to the ASCII encoded length, but that's not necessarily true. This is a case of using a value from one domain in another. NSString provides a method that you should use instead:int stringLength = [self lengthOfBytesUsingEncoding:NSASCIIStringEncoding];An equivalent, and probably even clearer way to handle this is to get your length from the C-native function, which makes sense since that's the string you're iterating over in the first place:size_t stringLength = strlen(_string);