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

  • Home
  • SEARCH
  • 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 800021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:13:31+00:00 2026-05-14T23:13:31+00:00

Here I am iterating through an array of NSDictionary objects (inside the parsed JSON

  • 0

Here I am iterating through an array of NSDictionary objects (inside the parsed JSON response of the EXCELLENT MapQuest directions API). I want to build up an HTML string to put into a UIWebView.

My code says:

for (NSDictionary *leg in legs ) {
    NSString *thisLeg = [NSString stringWithFormat:@"<br>%@ - %@", [leg valueForKey:@"narrative"], [leg valueForKey:@"distance"]];
    NSLog(@"This leg's string is %@", thisLeg);
    [directionsOutput appendString:thisLeg];
}

The content of directionsOutput (which is an NSMutableString) contains ALL the values for [leg valueForKey:@"narrative"], wrapped up in parens, followed by a hyphen, followed by all the parenthesized values for [leg valueForKey:@"distance"]. So I put in that NSLog call… and I get the same thing there! It appears that the for() is somehow batching up our output values as we iterate, and putting out the output only once.

How do I make it not do this but instead do what I actually want, which is an iterative output as I iterate?

Here’s what NSLog gets. Yes, I know I need to figure out NSNumberFormatter. 😉

This leg's string is (
    "Start out going NORTH on INFINITE LOOP.",
    "Turn LEFT to stay on INFINITE LOOP.",
    "Turn RIGHT onto N DE ANZA BLVD.",
    "Merge onto I-280 S toward SAN JOSE.",
    "Merge onto CA-87 S via EXIT 3A.",
    "Take the exit on the LEFT.",
    "Merge onto CA-85 S via EXIT 1A on the LEFT toward GILROY.",
    "Merge onto US-101 S via EXIT 1A on the LEFT toward LOS ANGELES.",
    "Take the CA-152 E/10TH ST exit, EXIT 356.",
    "Turn LEFT onto CA-152/E 10TH ST/PACHECO PASS HWY. Continue to follow CA-152/PACHECO PASS HWY.",
    "Turn SLIGHT RIGHT.",
    "Turn SLIGHT RIGHT onto PACHECO PASS HWY/CA-152 E. Continue to follow CA-152 E.",
    "Merge onto I-5 S toward LOS ANGELES.",
    "Take the CA-46 exit, EXIT 278, toward LOST HILLS/WASCO.",
    "Turn LEFT onto CA-46/PASO ROBLES HWY. Continue to follow CA-46.",
    "Merge onto CA-99 S toward BAKERSFIELD.",
    "Merge onto CA-58 E via EXIT 24 toward TEHACHAPI/MOJAVE.",
    "Merge onto I-15 N via the exit on the LEFT toward I-40/LAS VEGAS.",
    "Keep RIGHT to take I-40 E via EXIT 140A toward NEEDLES (Passing through ARIZONA, NEW MEXICO, TEXAS, OKLAHOMA, and ARKANSAS, then crossing into TENNESSEE).",
    "Merge onto I-40 E via EXIT 12C on the LEFT toward NASHVILLE (Crossing into NORTH CAROLINA).",
    "Merge onto I-40 BR E/US-421 S via EXIT 188 on the LEFT toward WINSTON-SALEM.",
    "Take the CLOVERDALE AVE exit, EXIT 4.",
    "Turn LEFT onto CLOVERDALE AVE SW.",
    "Turn SLIGHT LEFT onto N HAWTHORNE RD.",
    "Turn RIGHT onto W NORTHWEST BLVD.",
    "1047 W NORTHWEST BLVD is on the LEFT."
) - (
    0.0020000000949949026,
    0.07800000160932541,
    0.14000000059604645,
    7.827000141143799,
    5.0329999923706055,
    0.15299999713897705,
    5.050000190734863,
    20.871000289916992,
    0.3050000071525574,
    2.802999973297119,
    0.10199999809265137,
    37.78000259399414,
    124.50700378417969,
    0.3970000147819519,
    25.264001846313477,
    20.475000381469727,
    125.8580093383789,
    4.538000106811523,
    1693.0350341796875,
    628.8970336914062,
    3.7990000247955322,
    0.19099999964237213,
    0.4099999964237213,
    0.257999986410141,
    0.5170000195503235,
    0
)
  • 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-05-14T23:13:32+00:00Added an answer on May 14, 2026 at 11:13 pm

    [leg valueForKey:@"narrative"] seems to return an array of strings, while [leg valueForKey:@"distance"] returns an array of NSNumbers. There’s only one objects in legs.

    I cannot see why the “<br>” is missing in the posted output, though.

    Fast enumeration does nothing funny with your output.

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

Sidebar

Ask A Question

Stats

  • Questions 407k
  • Answers 407k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The canonical example on the Microsoft stack for T-SQL deployment… May 15, 2026 at 6:37 am
  • Editorial Team
    Editorial Team added an answer Don't forward declare std:ifstream - just import <iosfwd> instead. ifstream… May 15, 2026 at 6:37 am
  • Editorial Team
    Editorial Team added an answer Actually, I'm almost sure that there are more useful traces… May 15, 2026 at 6:37 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.