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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:51:54+00:00 2026-05-26T12:51:54+00:00

I am doing some operations in for loop with nsmutablearray’ s data. But sometimes

  • 0

I am doing some operations in for loop with nsmutablearray’ s data. But sometimes it work sometimes it gives me an error like ‘array index 3 empty array’ at this line :

else if (min>[[enyakinarray objectAtIndex:i] floatValue]) 

full code :

for (int i=0; i<[ws3.CustomerID count]; i++) {

    //radian hesaplaması
    float total = [first floatValue];
    float theta = total * M_PI/180;
    float total2 = [second floatValue];
    float theta2 = total2 * M_PI/180;
    float total3 = [[ws3.Latitude objectAtIndex: i]  floatValue];
    float theta3 = total3 * M_PI/180;
    float total4 = [[ws3.Longitude objectAtIndex: i] floatValue];
    float theta4 = total4 * M_PI/180;


     distance = 6371 * acos(cos(theta) * cos(theta3)
                           * cos(theta4 - theta2)
                           + sin(theta) * sin( theta3)) ;

    NSLog(@"xxxxx %f",distance);

    num = [NSNumber numberWithFloat:distance];
    [enyakinarray  addObject:num];
    NSLog(@"asasasas %@",enyakinarray);

}

float min;
NSString *s;
for (int i=0; i<[enyakinarray count]; i++) {
   if(i==0)
   { 
    min = [[enyakinarray objectAtIndex:i] floatValue];
    s= [ws3.CustomerName objectAtIndex:i];
   } 
   else if (min>[[enyakinarray objectAtIndex:i] floatValue])
            {
            min= [[enyakinarray objectAtIndex:i] floatValue];
            s = [ws3.CustomerName objectAtIndex:i];
            }
    enyakinfirma.text=s;
   }

How can I solve this?

  • 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-26T12:51:54+00:00Added an answer on May 26, 2026 at 12:51 pm

    This is strange but should be really easy to debug. Just write

    NSLog("First array: %@", enyakinarray)
    NSLog(@"Second array: %@", ws3.CustomerName)
    NSLog(@"Second array: %@", ws3.CustomerID)
    

    before your for and you should see the problem very quickly. Maybe you are changing the array contents somewhere between its creation and usage?

    However, I see a design problem there. Your code uses several separate arrays CustomerName, CustomerID and enyakinarray Latitude and Longitude which contain values of a single entity Customer (name, id, latitude, longitude and distance). Maybe you could create an object Customer with these properties and mantain only one array of customers? Good OOP design helps you prevent this type of errors 🙂

    And you can merge the two cycles into one:

    
    float minDistance = FLT_MAX;
    NSUInteger customerIndex = 0;
    
    for (NSUInteger i = 0; i < [ws3.CustomerID count]; i++) {
        /* distance calculation code ... */
    
        float distance = 6371 * acos(cos(theta) * cos(theta3)
                               * cos(theta4 - theta2)
                               + sin(theta) * sin(theta3));
    
        if (distance < minDistance) {
            minDistance = distance;
            customerIndex = i;
        }
    }
    
    enyakinfirma.text = [ws3.CustomerName objectAtIndex:customerIndex];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After doing some work with Ruby, Rails, and RSpec last summer and I learned
I am running two separate threads in C, both doing some operations. Both threads
I have been doing some unsafe bitmap operations and have found out that increasing
I am doing some game design, and decided that I want a data centric
I'm doing some Drag and Drop operations, and I want to use a visual
Doing some jquery animation. I have certain divs set up with an attribute of
While doing some JavaScript performance tests I came up with the following piece of
While doing some random experimentation with a factorial program in C, Python and Scheme.
While doing some refactoring I've found that I'm quite often using a pair or
I`m doing some web.config modifications with SPWebConfigModification class. When adding them to WebApplication and

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.