Skip navigation

Program received signal: "EXC_BAD_ACCESS"

981 Views 15 Replies Latest reply: Jun 25, 2012 5:04 PM by TheNavigator RSS
1 2 Previous Next
TheNavigator Calculating status...
Currently Being Moderated
Jun 20, 2012 6:00 AM

[internalExpression addObject:[NSNumber numberWithDouble:operand]];

 

[internalExpression addObject:[NSString stringWithString:operation]];

 

None of these work while I'm sure that both operation and operand have something in there. I've debugged it and saw that internalExpression just points to 0x0, which is obviously nil. Do I need to initialize it? Although I use NSString without initialization. Both are instance variables by the way.

Xcode, Mac OS X (10.6.7), Xcode 4.0.1
  • xnav Level 5 Level 5 (6,625 points)
    Currently Being Moderated
    Jun 20, 2012 8:28 AM (in response to TheNavigator)

    @"x", 2, @"a", 4, @"b", 8, nil


    For one thing 2,4, and 8 are not valid keys.

  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Jun 20, 2012 2:53 PM (in response to TheNavigator)

    Anything inside an "NS" container must be an object. If you want to store a number, store an NSNumber.

  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Jun 22, 2012 5:11 AM (in response to TheNavigator)

    NSNumber doesn't respond to isEqualToString:. Keep values in an NSString until you are sure they are a valid number. This was true since the early days of C. Otherwise, an invalid conversion will just return 0, a valid number.

  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Jun 22, 2012 8:56 AM (in response to TheNavigator)

    You may have defined your fast enumeration variable as an NSString, but apparently the objects inside are NSNumbers. In Objective-C, the (NSWhatever *) is just syntactic sugar to help you read the program. Internally, everything is an id.

  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Jun 23, 2012 12:33 PM (in response to TheNavigator)

    You appear to be using NSNumbers as keys in your dictionary. Technically there isn't anything wrong with that. But if you enumerate over those keys you must use the correct type.

  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Jun 23, 2012 7:30 PM (in response to TheNavigator)

    You can only send the addObject: message to an NSMutableArray

  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Jun 24, 2012 7:04 AM (in response to TheNavigator)

    Assuming anExpression really is an NSMutableArray, you may be able to do that. "mutableCopy" might be a better idea. Offhand I don't know what you get if you do a "copy" on a mutable object.

     

    Also, you don't need to create a new string with the @"=" literal. You can just use it.

1 2 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.