0

I am attempting to incorporate a plist into my project. I have accomplish the extraction of the data from the plist to my project. Now I want to write back the modified data. For instance, I have a textField in which the data is stored as an integer. Now I want to capture that integer data and store it in an NSMutable Dictionary *temp using:

[temp setObject:<what goes here?> forKey:@"key"];

prior to writing it all out to the plist. All I end up getting is the pointer information and not the value of the textField into the dictionary. I am using the following to examine the dictionary:

for (id key in temp) {
 NSLog(@"entry %@ value %@", key, [temp valueForKey:key]);
}
Regexident
  • 29,441
  • 10
  • 93
  • 100
Jim Rogers
  • 11
  • 2

1 Answers1

1

What you want is something like:

[temp setObject:[NSNumber numberWithInteger:[textField integerValue]] forKey:@"key"];

if you're coding for OS X.

Or something like:

[temp setObject:[NSNumber numberWithInteger:[textField.text integerValue]] forKey:@"key"];

if you're coding for iOS.

Just to make sure OP doesn't miss edc1591's comment: NSDictionary implements a method objectForKey:, which should be used in favor of the generic KVC method valueForKey:. See this answer for more info on objectForKey: vs. valueForKey:

Edit: Overlooked OP mentioning the values being integers. Fixed answer. Edit: Added remark on valueForKey: usage.

Community
  • 1
  • 1
Regexident
  • 29,441
  • 10
  • 93
  • 100
  • The OP said ...I want to capture that integer data.... Seems like `[temp setObject:[NSNumber numberWithInteger:[textField integerValue]] forKey:@"key"];` would be better. – jscs Apr 05 '11 at 20:54
  • also, he needs to use `objectForKey:` not `valueForKey:` when reading from the dictionary – edc1591 Apr 05 '11 at 21:00
  • @edc1591: yeah, noticed it, but ignored it since it wasn't strictly related to OPs question/problem. But you're totally right, of course. Added a remark to my answer. – Regexident Apr 05 '11 at 21:08