简体   繁体   中英

NSMutableArray Exc_Bad_Access

I only have this code in m. file

 NSMutableArray * arrayOfBools;

   arrayOfBools=[[NSMutableArray alloc] initWithCapacity:1000];

NSNumber *ijk =(NSNumber*) 9;

       [arrayOfBools addObject:ijk];                 

Get error o this [arrayOfBools addObject:ijk];

You can't declare and set an NSNumber like this: NSNumber *ijk =(NSNumber*) 9; . This will set it to an integer (9).

Use this:

NSNumber *ijk = [NSNumber numberWithInt:9];

The third line, the declaration of the NSNumber is incorrect. if you are attempting to wrap a bool into a NSNumber, use NSNumber *test = [NSNumber numberWithBool:YES];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM