TNT*_*OOL 3 iphone objective-c nslog nsmutablearray ios
我看到一些类似的问题,但没有简单的答案.在我真正使用它们之前,我只是在玩NSMutableArray来感受它们.出于某种原因,当我尝试在数组上调用count时,它给了我一个EXC_BAD_ACCESS错误,我无法找出原因.
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
// Create window and make key
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[_window makeKeyAndVisible];
NSMutableArray* test = [[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:@"first!"], [NSString stringWithFormat:@"second!"], nil];
[test insertObject:[NSString stringWithFormat:@"inserted"] atIndex:0];
NSLog(@"%@", [test objectAtIndex:0]);
NSLog(@"%@", [test objectAtIndex:1]);
NSLog(@"%@", [test objectAtIndex:2]);
NSLog(@"%@", [test count]); //bad access here
}
Run Code Online (Sandbox Code Playgroud)
所有插入和访问除了计数方法工作都很好.我不明白为什么这不起作用,非常感谢一些帮助.谢谢!
该%@格式说明打印对象.返回值-count只是一个无符号整数.您应该使用该%u类型的格式说明符.
| 归档时间: |
|
| 查看次数: |
1726 次 |
| 最近记录: |