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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:08:54+00:00 2026-06-06T01:08:54+00:00

I’ve got a single-screen app in which you find two textfields (object and key)

  • 0

I’ve got a single-screen app in which you find two textfields (object and key) and a button (which should store the two Strings in a NSMutableArray. BTW: don’t be confused: “merken” is german for “remember” 😉

my Problem is, that I’d like to fill my NSMutableDictionary this way, but right now it can just save the Object and Key the very first time.

This is my according method:

-(IBAction)merken:(id)sender { 

    NSString *currentObject = [[NSString alloc] init];NSString *currentKey = [[NSString alloc] init];

    currentObject = [typedObject text];
    currentKey = [typedKey text];

    [dict setValue:currentObject forKey:currentKey];

    //Check if the stings have been added to the Dict.
    int checkLengh = [dict count];
    NSString * checkString = [[NSString alloc] initWithFormat:@"Das Dict hat %d Zeile(n)", checkLengh];
    [checkLabel setText:checkString];

    [typedObject resignFirstResponder];
    [typedKey resignFirstResponder];
}

Any Ideas? I’ve been working on it all day…

  • 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-06T01:08:56+00:00Added an answer on June 6, 2026 at 1:08 am

    The answer is not in the code you have posted; to figure that out where dict is declared and how it is setup etc. needs to be known; but there are some things which might point to what has gone wrong.

    First you declare your strings as follows:

    NSString *currentObject = [[NSString alloc] init];
    

    This is completely wrong for strings (it is not for all types). An NSString is an immutable object and must be given a value when created. However a variable of type NSString * contains a reference to a string, or nil – for when it is referencing nothing. You only need:

    NSString *currentObject;
    

    To declare the variable which will hold the reference to the NSString object. If you wish you can go a little further an use:

    NSString *currentObject = nil;
    

    So the variable starts with a known value (otherwise local variables will contain a garbage value, instance variables are automatically set to nil/0/etc. as appropriate). However you will be immediately assigning a value so assigning nil is not needed – there is no chance you’ll accidentally use a garbage value.

    Getting this wrong suggests you might be unclear about how objects and references work, and you may have made mistakes when declaring and allocating your NSMutableDictionary.

    Second you should use setObject:forKey: to set the key/value:

    [dict setObject:currentObject forKey:currentKey];
    

    These two methods are subtly different, you usually want setObject; look at the documentation for the differences.

    HTH

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

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from

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.