致电 NSDictionary 后我得到一些不相关的答案
我尝试了下面的代码:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * str1 = @"program";
NSArray * alphabets = [NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z",nil];
NSMutableDictionary * alphaToNum = [NSMutableDictionary dictionary];
NSMutableDictionary * numToAlpha = [NSMutableDictionary dictionary];
NSInteger index =0;
int shifter = 5;
for(NSString * character in alphabets){
index++;
[alphaToNum setObject:[NSNumber numberWithInteger:index] forKey:character];
[numToAlpha setObject:character forKey:[NSNumber numberWithInteger:index]];
}
NSRange * rng = {0,0};
NSLog(@"-------");
//NSLog(@"%@" , [str1 substringWithRange:NSMakeRange(1, 1)]);
for(int i=0;i<[str1 length];i++)
{
NSString * ss = [str1 substringWithRange:NSMakeRange(i, 1)];
NSInteger i = [alphaToNum valueForKey:ss];
i = (i + 5);
NSLog(@"%d",i); //last code
}
这是我得到的最后一个代码
2011-10-24 13:20:08.289 cipher[22732:a0f] 1103808
2011-10-24 13:20:08.290 cipher[22732:a0f] 1101168
2011-10-24 13:20:08.290 密码[22732:a0f] 1103200
2011-10-24 13:20:08.290 密码[22732:a0f] 1103616
2011-10-24 13:20:08.291 cipher[22732:a0f] 1103584
甚至有时是
“EXC_BAD_ACCESS”。
这是完全错误的!
I tried below code :
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * str1 = @"program";
NSArray * alphabets = [NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z",nil];
NSMutableDictionary * alphaToNum = [NSMutableDictionary dictionary];
NSMutableDictionary * numToAlpha = [NSMutableDictionary dictionary];
NSInteger index =0;
int shifter = 5;
for(NSString * character in alphabets){
index++;
[alphaToNum setObject:[NSNumber numberWithInteger:index] forKey:character];
[numToAlpha setObject:character forKey:[NSNumber numberWithInteger:index]];
}
NSRange * rng = {0,0};
NSLog(@"-------");
//NSLog(@"%@" , [str1 substringWithRange:NSMakeRange(1, 1)]);
for(int i=0;i<[str1 length];i++)
{
NSString * ss = [str1 substringWithRange:NSMakeRange(i, 1)];
NSInteger i = [alphaToNum valueForKey:ss];
i = (i + 5);
NSLog(@"%d",i); //last code
}
and this is what I get for the last code
2011-10-24 13:20:08.289 cipher[22732:a0f] 1103808
2011-10-24 13:20:08.290 cipher[22732:a0f] 1101168
2011-10-24 13:20:08.290 cipher[22732:a0f] 1103200
2011-10-24 13:20:08.290 cipher[22732:a0f] 1103616
2011-10-24 13:20:08.291 cipher[22732:a0f] 1103584
or even sometimes
“EXC_BAD_ACCESS”.
which is totally wrong!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将返回一个 NSNumber 对象,而不是一个 NSInteger。
如下所示,
关于崩溃,我们只能在查看崩溃日志后才能回答。那会更有帮助。
This will return an NSNumber object, not an NSInteger.
Make that line as follows,
And regarding the crash, we can answer only after looking at the crash log. That would be more helpful.