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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:22:06+00:00 2026-06-11T21:22:06+00:00

I made this simple code: PO(self.last10000Places); PO(PlaceMark); NSMutableArray *placemarks= [NSMutableArray arrayWithArray:PlaceMark]; PO(placemarks);//Breakpoint1 [placemarks removeObjectsInArray:self.last10000Places];

  • 0

I made this simple code:

PO(self.last10000Places);
PO(PlaceMark);
NSMutableArray *placemarks= [NSMutableArray arrayWithArray:PlaceMark];
PO(placemarks);//Breakpoint1
[placemarks removeObjectsInArray:self.last10000Places];
PO(placemarks);//Breakpoint2
[self.last10000Places addObjectsFromArray:placemarks];

Here PO is simply my macro

#define CLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#define PO(x) CLog(@#x ": %@", x)
#define PD(x) CLog(@#x ": %f", x)

Now, I am aware that nsmutablearray need to have isEqual implemented.

So I put this code:

@interface CLLocation  (equal)
- (BOOL)isEqual:(CLLocation*)other;
@end

@implementation CLLocation  (equal)

- (BOOL)isEqual:(CLLocation*)other {


    if ([self distanceFromLocation:other] ==0)
    {
        return true;
    }
    return false;
}
@end
@interface CLPlacemark (equal)
- (BOOL)isEqual:(CLPlacemark*)other;
@end

@implementation CLPlacemark (equal)

- (BOOL)isEqual:(CLPlacemark*)other {
    PO(self);
    PO(other);
    if (![self.name isEqual:other.name])
    {
        return false;
    }
    if (![self.location isEqual:other.location ])
    {
        return false; //NEVER called
    }
    return true;//breakpoint3 but strange result
}


@end

Then I step through the code. Now this is what’s strange.

at breakpoint1 I saw:

2012-09-22 21:40:53.959 GetAllDistricts[18381:c07] <0x74a7480 SDViewController.m:(82)> placemarks: (
    "Ross Sea, Ross Sea @ <-77.43947520,-168.68218520> +/- 100.00m, region (identifier <-75.73637772,-0.00216940> radius 2140218.36) <-75.73637772,-0.00216940> radius 2140218.36m"

at breakpoint3 I saw:
2012-09-22 21:41:22.964 GetAllDistricts[18381:c07] <0xd77fab0 SDViewController.m:(37)> self: Alexander Island, Antarctica @ <-71.05224390,-70.87965290> +/- 100.00m, region (identifier <-70.73927686,-71.91489801> radius 258243.49) <-70.73927686,-71.91489801> radius 258243.49m
2012-09-22 21:41:22.964 GetAllDistricts[18381:c07] <0xd77fab0 SDViewController.m:(38)> other: South Atlantic Ocean, South Atlantic Ocean, Antarctica @ <-42.60533670,-21.93128480> +/- 100.00m, region (identifier <-41.51023865,-31.60774370> radius 4958095.65) <-41.51023865,-31.60774370> radius 4958095.65m
2012-09-22 21:41:22.965 GetAllDistricts[18381:c07] <0xd787390 SDViewController.m:(37)> self: South Atlantic Ocean, South Atlantic Ocean, Antarctica @ <-42.60533670,-21.93128480> +/- 100.00m, region (identifier <-41.51023865,-31.60774370> radius 4958095.65) <-41.51023865,-31.60774370> radius 4958095.65m
2012-09-22 21:41:22.965 GetAllDistricts[18381:c07] <0xd787390 SDViewController.m:(38)> other: South Atlantic Ocean, South Atlantic Ocean, Antarctica @ <-42.60533670,-21.93128480> +/- 100.00m, region (identifier <-41.51023865,-31.60774370> radius 4958095.65) <-41.51023865,-31.60774370> radius 4958095.65m

It’s obvious that placemarks contains Ross Sea. So what the hell removeObjectsinArray call isEqual with South Atlantic Ocean?

Also the Ross Sea is not removed from placemarks by breakpoint2.

I implemented isEqual I do not implement hash

Is this the problem?

  • 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-06-11T21:22:07+00:00Added an answer on June 11, 2026 at 9:22 pm

    I have figured out what the problem is. Implementing -(NSUInteger) hash somehow fix the problem.

    The documentation says that we have to override hash when we override isEqual

    Looks like removeObjects use the hash for optimization and figure out that the hash is unequal and conclude that isEqual will return false without checking.

    So I simply add this code:

    @interface CLLocation  (equal)
    - (BOOL)isEqual:(CLLocation*)other;
    @end
    
    @implementation CLLocation  (equal)
    
    - (BOOL)isEqual:(CLLocation*)other {
    
    
        if ([self distanceFromLocation:other] ==0)
        {
            return true;
        }
        return false;
    }
    
    - (NSUInteger) hash
    {
        NSUInteger theHash = (NSUInteger) (self.coordinate.latitude *360 + self.coordinate.longitude);
        CLog(@"thehash %d",theHash);
        return theHash;
    }
    @end
    @interface CLPlacemark (equal)
    - (BOOL)isEqual:(CLPlacemark*)other;
    @end
    
    @implementation CLPlacemark (equal)
    
    - (BOOL)isEqual:(CLPlacemark*)other {
        PO(self);
        PO(other);
        if (![self.name isEqual:other.name])
        {
            return false;
        }
        if (![self.location isEqual:other.location ])
        {
            return false;
        }
        return true;
    }
    
    -(NSUInteger) hash
    {
        return self.name.hash;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made this simple function to filter the data. I add the symbols that
I recently made this simple navigation where you have a couple links that have
I'm working on a bigger project atm, but I made this simple example to
So I made this (very simple) program with a swing GUI with NetBeans, and
This is simple text detection video made using an opencv. Any ideas how was
This module is part of a simple todo app I made with Python... def
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
I'm not sure if this possible but probably is fairly simple. I've made a
Using Java sockets, I made a simple server. This works because it sends data
Just wondering about some practice about this; I have made a simple visual C#

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.