最近我添加了一個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