UIMutableIndexPath and NSIndexPath return true for isEqual: but have different hash values
| Originator: | chellmuth | ||
| Number: | rdar://15806671 | Date Originated: | 2014/01/13 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | 7.0 |
| Classification: | Reproducible: | Always |
Summary:
In iOS7, the hash implementation for UIMutableIndexPath and NSIndexPath appear to have changed. If you have a mutable and non-mutable index path with the same value, they return true for isEqual: but have differing hash values. In iOS6 the hash values would be equal.
The UITableViewDelegate method - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath provides a UIMutableIndexPath. If, for example, the program keeps an NSSet of NSIndexPaths and checks the membership of the supplied indexPath, there will be false negatives due to the hash difference.
Steps to Reproduce:
Run the attached Xcode project, or:
Implement the UITableViewDelegate method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
with the following code:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *copiedIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
if ([indexPath isEqual:copiedIndexPath]
&& indexPath.hash != copiedIndexPath.hash
) {
NSLog(@"if isEqual: is true, hash should be equal");
NSLog(@"%@", indexPath);
NSLog(@"%@ %@", [indexPath class], [copiedIndexPath class]);
NSLog(@"%d", [indexPath isEqual:copiedIndexPath]);
NSLog(@"%u %u", copiedIndexPath.hash, indexPath.hash);
}
return 0.f;
}
Expected Results:
The if statement would never evaluate to true.
Actual Results:
The if statement evaluates to true for index paths that are not (0, 0).
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Duped as 18094838