NSMutableArray Crashing App

In one class, I define an NSMutableArray with getters and setters:

@interface ArrayClass : NSObject {
    NSMutableArray *array;
}
@property (nonatomic, strong) NSMutableArray *array;

@end

Then within the implementation file, I alloc init the mutable array:

#import "ImageUploader.h"

@implementation ArrayClass
@synthesize array;

- (id)init {
    self = [super init];
    if (self != nil) {
        NSLog(@"ArrayClass inited");
        array = [[NSMutableArray alloc] init];
    }
    return self;
}

@end

Then I initialize an instance of this class from another class:

ArrayClass *arrayClass = [[ArrayClass alloc] init];
                [arrayClass.array addObject:image];
                NSUInteger count = [arrayClass.array count];
                NSLog(@"%@", count);

But when I try to add an object to the mutable array, the app crashes and Xcode 4.3 shows:

Removing the addObject call makes the app run fine. What am I doing wrong that would cause the app to crash?

Answers


This is wrong:

NSUInteger count = [arrayClass.array count];
NSLog(@"%@", count);

You want:

NSLog(@"%u", count);

%@ is used to specify that the argument is an object. However, an NSUInteger is a primitive value, not an object. You use %u for unsigned ints.


Need Your Help

Choosing a schema for SQL lookup table in the context of LINQ to SQL: sql_variant or multiple fields

.net sql-server sql-server-2005 linq-to-sql types

I have a question similar to this but in the context of L2S. I want to create a lookup table to store values that could be one of several possible datatypes. As suggested in the referenced question...

duplicate item allowed in shopping cart but need warning msg

java cart

I have a ShoppingCart app that can add/remove Book objects

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.