Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does string show up in NSDictionary with quotes, but others don't? [duplicate]

So I have an NSMutableDictionary that I populate, but when I output the contents to NSLog, the key and value for the entries entered in the for loop show up differently, and the final NSLog call doesn't even output anything. What's going on here??? Please help! Why are the quotes around the entries added in the for loop???

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                            numberOfPhotosAsString, @"PackageFileCount",
                            wtID, @"wtID",
                            uploadType, @"type",
                            nil];
    for (int i= 0; i < photos.count; i++)
    {
        NSString *finalFileName = [fileNameBase stringByAppendingFormat:@"%i", i];
        [params setObject:[[fileNames objectAtIndex:i] stringByAppendingString:@".jpg"] forKey:finalFileName];
        // This one doesn't do anything differently:
        //[params setValue:[[fileNames objectAtIndex:i] stringByAppendingString:@".jpg"] forKey:[fileNameBase stringByAppendingFormat:@"%i", i]];
    }
    NSLog(@"Params: %@", params);
    NSLog(@"Value: %@", [params objectForKey:@"SourceName_0"]);

Output of NSLog (I only added one value in the for loop: "SourceName_0" = "tbyg.jpg", but why the quotes around "SourceName_0"??? Whatever is happening here is preventing me from accessing that dictionary entry...

Log:

2012-05-09 12:38:26.448 PhotoUp[6231:707] Params: {
    PackageFileCount = 1;
    "SourceName_0" = "tbyg.jpg";
    type = T;
    wtID = "6bcb4126-4bbe-4b3d-be45-9a06cf56a22f";
}
2012-05-09 12:38:26.449 PhotoUp[6231:707] Value: (null)
like image 974
HackyStack Avatar asked May 09 '12 16:05

HackyStack


1 Answers

The quotes appear because the string contains something besides basic alphanumerics — in this case, an underscore. It's the same reason "tbyg.jpg" and "6bcb4126-4bbe-4b3d-be45-9a06cf56a22f" have quotes (they contain a dot and dashes, respectively). That's just how the description method works. It wouldn't cause your second log to fail.

like image 148
Chuck Avatar answered Oct 03 '22 01:10

Chuck