Last active
April 24, 2018 18:44
-
-
Save Shilo/6409077 to your computer and use it in GitHub Desktop.
A category for NSString to reverse string.
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+Reverse.h | |
// | |
// Created by Shilo White on 9/1/13. | |
// Copyright (c) 2013 Shilocity Productions. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSString (Reverse) | |
@property (nonatomic, readonly) NSString *reversedString; | |
@end |
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+Reverse.m | |
// | |
// Created by Shilo White on 9/1/13. | |
// Copyright (c) 2013 Shilocity Productions. All rights reserved. | |
// | |
#import "NSString+Reverse.h" | |
@implementation NSString (Reverse) | |
- (NSString *)reversedString | |
{ | |
NSMutableString *reversedString = [NSMutableString stringWithCapacity:self.length]; | |
[self enumerateSubstringsInRange:NSMakeRange(0,self.length) | |
options:(NSStringEnumerationReverse | NSStringEnumerationByComposedCharacterSequences) | |
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | |
[reversedString appendString:substring]; | |
}]; | |
return reversedString; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment