最近我添加了一个rot13函数到我的项目,所以我可以rot13一个字符串我想要的。示例代码是通过互联网找到的。在我旋转了一个字符串之后,我得到了一个低内存警告,并且100%确定这是由于腐烂函数引起的。在rot13之前没有低内存警告。 这里是我的代码: rot13.hRot13实现后的低内存警告
#import <Foundation/NSString.h>
@interface NSString (rot13)
+ (NSString *)rot13:(NSString *)theText;
@end
rot13.m
#import "rot13.h"
@implementation NSString (rot13)
+ (NSString *)rot13:(NSString *)theText {
NSMutableString *holder = [[NSMutableString alloc] init];
unichar theChar;
int i;
for(i = 0; i < [theText length]; i++) {
theChar = [theText characterAtIndex:i];
if(theChar <= 122 && theChar >= 97) {
if(theChar + 13 > 122)
theChar -= 13;
else
theChar += 13;
[holder appendFormat:@"%hhd", (char)theChar];
} else if(theChar <= 90 && theChar >= 65) {
if((int)theChar + 13 > 90)
theChar -= 13;
else
theChar += 13;
[holder appendFormat:@"%C", theChar];
} else {
[holder appendFormat:@"%C", theChar];
}
}
return [NSString stringWithString:holder];
}
@end
而且我ROT13我的字符串是这样的:
NSString *mystring=[defaults stringForKey:@"name"];
NSString *rotted = [NSString rot13:mystring];
任何帮助吗?我应该释放一些东西吗?为什么这个简单的任务称为低内存警告?
这段代码是用ARC还是MRC编译的? – rmaddy 2013-05-11 18:10:25
它是用ARC编译的。 – Theodoros80 2013-05-11 18:16:53
然后没有什么可以发布的。 – rmaddy 2013-05-11 18:38:56