Created
June 17, 2015 16:16
-
-
Save dniswhite/b408cdf3876cef286f61 to your computer and use it in GitHub Desktop.
Reverse an NSString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSString *) reverseString: stringToReverse { | |
NSMutableString *reversedString = [NSMutableString string]; | |
NSInteger charIndex = [stringToReverse length]; | |
while (charIndex > 0) { | |
charIndex--; | |
NSRange subStrRange = NSMakeRange(charIndex, 1); | |
[reversedString appendString:[stringToReverse substringWithRange:subStrRange]]; | |
} | |
return reversedString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment