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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:44:46+00:00 2026-05-16T15:44:46+00:00

What does mean? I get this error when trying to iterate through a file

  • 0

What does mean? I get this error when trying to iterate through a file in Cocoa obj-c.

I can’t find any information on the web.

Would appreciate some help. Thanks.

EDIT

I’ve been following this tutorial (link) to preload Core Data. I’ve tried creating a Cococa application and have also tried doing this from within my iPhone app. I think all my setup code for Core Data is fine. Whenever this method is called I get EXEC BAD ACCESS.

- (void)loadInitialData
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    // name ZSTREET_1   ZSTREET_2   ZCITY   ZZIP    ZURL    ZTEL    latitude    longitude

    NSString *path = [[NSBundle mainBundle] pathForResource:@"placesdata" ofType:@"txt"];

    NSString *fileString = [NSString stringWithContentsOfFile:path]; // reads file into memory as an NSString
    NSArray *lines = [fileString componentsSeparatedByString:@"\r"]; // each line, adjust character for line endings
    NSManagedObjectContext *context = [self managedObjectContext];
    for (NSString *line in lines)

    {   
        NSLog(line);

        NSString* string = [[NSString alloc] initWithUTF8String:line];
        NSArray *parts = [string componentsSeparatedByString:@"\t"];
        // value mapping
        NSString *name = [parts objectAtIndex:0];
        NSString *street_1 = [parts objectAtIndex:1];
        NSString *street_2 = [parts objectAtIndex:2];
        NSString *city = [parts objectAtIndex:3];
        NSString *zip = [parts objectAtIndex:4];
        NSString *url = [parts objectAtIndex:5];

        NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
        [f setNumberStyle:NSNumberFormatterDecimalStyle];

        NSNumber *latitude = [f numberFromString:[parts objectAtIndex:6]];
        NSNumber *longitude = [f numberFromString:[parts objectAtIndex:7]];
        [f release];
        // splitting the parts to create the objects

        Place *place = (Place *)[NSEntityDescription insertNewObjectForEntityForName:@"Place" inManagedObjectContext:context];
        Address *address = (Address *)[NSEntityDescription insertNewObjectForEntityForName:@"Address" inManagedObjectContext:context];
        Location *location = (Location *)[NSEntityDescription insertNewObjectForEntityForName:@"Location" inManagedObjectContext:context];

        // set attributes
        [place setValue:name forKey:@"name"];
        [address setValue:street_1 forKey:@"street_1"];
        [address setValue:street_2 forKey:@"street_2"];
        [address setValue:city forKey:@"city"];
        [address setValue:zip forKey:"@zip"];
        [address setValue:url forKey:@"url"];
        [location setValue:latitude forKey:@"latitude"];
        [location setValue:longitude forKey:@"longitude"];

        // link the objects together
        [place setValue:address forKey:@"address"];
        [place setValue:location forKeyPath:@"address.location"];

        [string release];
    }
    NSLog(@"Done initial load");
    NSError *error; 
    if (![context save:&error]) {
        NSLog(@"Error saving: %@", error);
    }
    [context release];
    [pool drain];


}
  • 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-16T15:44:47+00:00Added an answer on May 16, 2026 at 3:44 pm

    This line is wrong and should produce a compiler warning:

    NSString* string = [[NSString alloc] initWithUTF8String:line];
    

    The method initWithUTF8String: expects an UTF-8 encoded C string and not a NSString object.

    Before you continue you should fix all compiler warnings! And you also should check that the parts array actually contains as many objects as you expect. You also need to use a format string with NSLog, you might even crash there if your line contains any % characters.

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

Sidebar

Related Questions

I am trying to iterate through this loop: for doc in coll.find() I get
Does anyone know what these error's mean? I get this when I click a
Does anyone know a way to get the mean amplitude of a .wav file
Does this mean I can't update another table from a trigger if I'm using
When trying to run my project I get this error and I don´t know
When trying to open a file using this command: $fd = fopen('majestic_files/majestic_record.txt','w'); I get
I'm trying to use OpenID on my site but I get this error: Protocol
What does this mean: Next add reference to: MySql.Data actually I have downloaded mysql
I am trying to debug this bizarre 404 error that surfaced in my Django
I'm trying to build a makefile and after about 5 seconds, I get this

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.