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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:22:54+00:00 2026-05-23T16:22:54+00:00

I store the data into an NSMutableArray The issue is that the ABRecord is

  • 0

I store the data into an NSMutableArray

The issue is that the ABRecord is sometimes incomplete. For example, I am expecting the user to have the following data

First Name
Last Name
Street Address
City
State
Zip
Country

If City, State, Zip are missing then I crash. So is there a better way to check?

Here is my code

- (NSString *)getCityStateAndZip
{
    NSString* temp = [addressArray objectAtIndex:0];
    if (temp != nil) {
        NSArray *listItems = [temp componentsSeparatedByString:@","];
        NSMutableArray* tempArray = [NSMutableArray arrayWithArray:listItems];
        [tempArray removeObjectAtIndex:0];
        if ([tempArray count] > 2) {
            [tempArray removeObjectAtIndex:3];
        }
        temp = @"";
        for (NSString* element in tempArray) {
            if (element != nil) {
                //NSLog(@"%@", element);
                if ([element isEqualToString:@"(null)"]) {
                    NSLog(@"record has a null entry");
                }
                temp = [temp stringByAppendingString:element];
                temp = [temp stringByAppendingString:@", "];
            }
        }
        if ([temp length] > 1) {
            temp = [temp substringToIndex:[temp length] -2];
        }
    }
    return temp;
}

Here is a ‘po tempArray’ before we start removing elements.

(gdb) po tempArray
<__NSArrayM 0x5a6ee20>(
1 Main Street ,
Trenton ,
NJ ,
08601 ,
United States
)

Thanks

If you have a better way of handling this, I’d love to know.

The line which crashes the app is

[tempArray removeObjectAtIndex:3];

I know why it crashes. If the city, state, zip are missing then it can’t remove the item if the array is smaller than 4.

  • 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-23T16:22:55+00:00Added an answer on May 23, 2026 at 4:22 pm

    While you search for a better more permanent solution, and unless I am missing something in your code, wouldn’t this at least stop the crash?

        if ([tempArray count] > 3) {
            [tempArray removeObjectAtIndex:3];
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object I am using to store document meta data into a
I have classes that store data, and methods to go get data for individual
I have a class that retrieves data from core data and stores it into
I do have a loop which store data into mysql... /connect to your database
struct.unpack will unpack data into a tuple. Is there an equivalent that will store
is there any easy way of store XML data into core data? Currently, my
I am in need of a lightweight way to store dictionaries of data into
I want to store the data returned by $_SERVER[REMOTE_ADDR] in PHP into a DB
I need to store a lot of data coming in from a server into
I need to recv() data from a socket and store it into a buffer,

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.