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 8131667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:09:13+00:00 2026-06-06T09:09:13+00:00

I am trying to assign objects in an NSMutableArray using this code – (IBAction)variablePressed:(UIButton

  • 0

I am trying to assign objects in an NSMutableArray using this code

- (IBAction)variablePressed:(UIButton *)sender {
NSString *variable = [sender currentTitle];
if (!_variableToBePassedIntoTheDictionary) _variableToBePassedIntoTheDictionary = [[NSMutableArray alloc] init];
[_variableToBePassedIntoTheDictionary replaceObjectAtIndex:0 withObject:variable];}

but when I run this program the program breaks at the last line, since I have set the debugger to show warnings if a Exception is raised. Running the program without breakpoints, the program gives SIGARBT and crashes. I then assign these values to a dictionary which would be passed to the Model for further calculations.

- (IBAction)testVariableValues:(id)sender {
if (!_variablesAssignedInADictionary) _variablesAssignedInADictionary = [[NSMutableDictionary alloc] init];
[_variablesAssignedInADictionary setObject:_digitToBePassedIntoTheVariable forKey:_variableToBePassedIntoTheDictionary];
NSLog(@"%@", _variablesAssignedInADictionary);}

P.S. I am new in Objective C, can anybody please explain when do we use

@synthesize someProperty;

vs

@synthesize someProperty = _someProperty;

Thank You!

  • 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-06-06T09:09:14+00:00Added an answer on June 6, 2026 at 9:09 am

    The first time the method is called you create the NSMutableArray and then attempt to replace an object which is not there. The reference says:

    - (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject
    

    The index of the object to be replaced. This value must not exceed
    the bounds of the array
    . Important Raises an NSRangeException if
    index is beyond the end of the array.

    And 0 will exceed the bounds of an empty array.

    Try this instead:

    - (IBAction)variablePressed:(UIButton *)sender
    {
        NSString *variable = [sender currentTitle];
        if (_variableToBePassedIntoTheDictionary == nil)
        {
            _variableToBePassedIntoTheDictionary = [[NSMutableArray alloc] init];
            [_variableToBePassedIntoTheDictionary addObject:variable];
        }
        else
        {
            [_variableToBePassedIntoTheDictionary replaceObjectAtIndex:0 withObject:variable];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to assign the output of this command ( that is in my
i'm trying to assign a parent's variable from the parent's child //Parent public class
I am trying to assign the min value of a char to a variable
I am currently trying to assign an event handler to dynamically created rectangle objects.
I am getting errors using a NSDictionary when trying to assign it's contents to
I am serializing objects to XML using System.Xml.Serialization and this requires me to have
I have been trying to assign value to an object array that is defined
I am trying to assign a custom type as a key for std::map .
I'm trying to assign values contained in a lookup table to multiple variables by
I am trying to assign a regular expression result to an array inside of

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.