Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6867035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:15:29+00:00 2026-05-27T03:15:29+00:00

if ([diamonds count] == 0) { [self toggleWinLevel]; } When diamonds is an NSMutableArray

  • 0
 if ([diamonds count] == 0) {
    [self toggleWinLevel];
}

When diamonds is an NSMutableArray and toggleWinLevel is an instance method, if I run this app it crashes on this line with an EXC_BAD_ACCESS:

 if ([diamonds count] == 0) {

It is is definitely to do with my array since this keeps on happening even when i assign an int or NSUInteger or NSNumber to my array’s count. My NSMutableArray is allocated and initialized. What is the problem?

UPDATE 1:

Ive allocated and initialized it in this method which DOES get called and i have NSLog which does log in the console for proof:

    -(void)setUpObjects {

NSLog(@"Setting Up Objects"); // This is printed in my console

[levelNumberLabel setHidden:YES];
diamonds = [[NSMutableArray alloc] init];
rocks = [[NSMutableArray alloc] init];

if (levelNumber < 3) {

    diamonds = [NSMutableArray arrayWithObjects:@"1", nil];

} else if (levelNumber > 2 <= 4) {

    diamonds = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", nil];

} else if (levelNumber > 4 <= 6) {

    diamonds = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"4", nil];

} else if (levelNumber > 6 <= 10) {

    diamonds = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", nil];

} else if (levelNumber > 10) {

    diamonds = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", nil];
}

if ([diamonds count] > 1 <= 2) {

    rocks = [NSMutableArray arrayWithObjects:@"1", @"2", nil];                 

} else if ([diamonds count] > 2 <= 5) {

    rocks = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", nil];

} else if ([diamonds count] > 5) {

    rocks = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"4", nil];
}

[self drawObjects];
}

BTW diamonds (the array) is an instance variable

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:15:29+00:00Added an answer on May 27, 2026 at 3:15 am

    You are first calling:

    diamonds = [[NSMutableArray alloc] init];
    

    but later calling, for example:

    diamonds = [NSMutableArray arrayWithObjects:@"1", nil];
    

    The second call will assign to diamonds an autoreleased object, you need to retain that object.

    There is an inconsistency in your code in that with your first call you have an retained object as opposed to an autoreleased object in the second call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is strange - I think? library(ggplot2) tf <- which(sapply(diamonds, is.factor)) diamonds.tf <- diamonds[,tf]
This line of code causes compiler to complain and enter a debug mode NSLog(@Attacker
Assigning an int, NSNumber and NSUInteger to an arrays count fails... this is my
I have an enum, that looks like this: enum Suit {Clubs, Diamonds, Hearts, Spades};
char *a[]={diamonds,clubs,spades,hearts}; char **p[]={a+3,a+2,a+1,a}; char ***ptr=p; cout<<*ptr[2][2]; why does it display h and please
The challenge The shortest code by character count to output a best-case blackjack hand
This code is taken from a SCJP practice test: 3. public class Bridge {
absolute newbie in this space so please adjust :-) this has to work on
This is the code I'm currently running: n <- 7 N <- 52 r
if you look on this page: http://www.lyricsinger.org/lyric/michel-sardou/c-est-ma-vie there are several black diamonds with question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.