• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trouble creating dictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble creating dictionary


  • Subject: Trouble creating dictionary
  • From: Dale Satterfield <email@hidden>
  • Date: Tue, 27 Sep 2011 18:21:07 -0700

I have the following code which creates two arrays of 97 elements each, then creates an NSDictionary.
However, the dictionary only has 30 elements in it, and reports no errors during creation. None of the keys should be a duplicate .

  tzKeys = [NSArray arrayWithObjects:TZ_Eniwetok,TZ_Kwajalein,TZ_Midway,TZ_Samoa,TZ_Hawaii,TZ_Alaska,TZ_Tijuana,TZ_LosAngeles,TZ_Pacific,TZ_Mountain,TZ_Phoenix,
            TZ_Central,TZ_Eastern,TZ_Bogota,TZ_Lima,TZ_Quito,TZ_Atlantic,TZ_Caracas,TZ_LaPaz,TZ_Santiago,TZ_Newfoundland,TZ_Brasilia,TZ_Buenos_Aires,TZ_MidAtlantic,TZ_Azores,TZ_CapeVerde,TZ_GMT,TZ_Mexico_City,TZ_CentralAmerica,TZ_London,TZ_Edinburgh,TZ_Dublin,TZ_Lisbon,TZ_Monrovia,TZ_Berlin,TZ_Rome,TZ_Amsterdam,TZ_Stockholm,TZ_Paris,TZ_Brussels,TZ_Prague,TZ_Belgrade,TZ_Bratislava,TZ_Budapest,TZ_Ljubljana,TZ_Athens,TZ_Helsinki,TZ_Istanbul,TZ_Minsk,TZ_Riga,TZ_Cairo,TZ_Bucharest,TZ_Harare,TZ_Praetoria,TZ_Jerusalem,TZ_Baghdad,TZ_Kuwait,TZ_Nairobi,TZ_Moscow,TZ_Volgograd,TZ_Tehran,TZ_Tblisi,TZ_Kabul,TZ_Karachi,TZ_Bombay,TZ_Madras,TZ_Calcutta,TZ_New_Delhi,TZ_Chennai,TZ_Almaty,TZ_Dhaka,TZ_Colombo,TZ_Novosibirsk,TZ_Bangkok,TZ_Jakarta,TZ_Irkutsk,TZ_Beijing,TZ_HongKong,TZ_Perth,TZ_Singapore,TZ_Taipei,TZ_Tokyo,TZ_Seoul,TZ_Yakutsk,TZ_Adelaide,TZ_Darwin,TZ_Brisbane,TZ_Melbourne,TZ_Sydney,TZ_Guam,TZ_Magadan,TZ_SolomonIslands,TZ_NewCaledonia,TZ_Fiji,TZ_MarshallIslands,TZ_Auckland,TZ_Wellington, nil];
    tzValues = [[NSMutableArray alloc] init];
    int i;
    int offsets[] = {-1200,-1200,-1100,-1100,-1000,-900,-800,-800,-800,-700,-700,-600,-500,-500,-500,-500,-400,-400,-400,-400,
                    -330,-300,-300,-200,-100,-100,0,0,0,0,0,0,0,0,100,100,100,100,100,100,100,100,100,100,100,200,200,200,200,200,200,200,200,200,200,
                    300,300,300,300,300,330,400,430,500,530,530,530,530,530,600,600,600,600,700,700,800,800,800,800,800,800,900,900,900,
                    930,930,1000,1000,1000,1000,1100,1100,1100,1200,1200,1200,1200,5555};

    for(i = 0; offsets[i] != 5555; i++)
    {
            [tzValues addObject:[NSNumber numberWithInt:offsets[i]]];
    }
    NSLog(@"i = %d elements in tzValues",i);    // i ends up at 97
    NSLog(@"tzValues says its count is %lu",[tzValues count]);  // Says count is 97
    NSLog(@"tzKeys says it's count is %lu",[tzKeys count]); // Says count is 97

    tzDict = [NSDictionary dictionaryWithObjects:tzKeys forKeys:tzValues];
    for(NSString *key in tzDict) NSLog(@"%@  %@",key, [tzDict objectForKey:key]);   // Prints 30 keys/objects
    for(NSString *key in tzKeys) NSLog(@"%@",key);  // Enumerate items in tzKeys    // Prints all 97 items
    for(NSNumber *aNum in tzValues) NSLog(@" the value in tzValues is %@",aNum);    // Prints all 97 items
    NSLog(@"tzDict says it's count of items is %lu",[tzDict count]);                // Says count is 30

Dale Satterfield
email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Trouble creating dictionary
      • From: Graham Cox <email@hidden>
    • Re: Trouble creating dictionary
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: controller question
  • Next by Date: Re: Trouble creating dictionary
  • Previous by thread: Re: debugging crashes in dyld?
  • Next by thread: Re: Trouble creating dictionary
  • Index(es):
    • Date
    • Thread