Latest | 1.0.1 |
---|---|
Homepage | https://github.com/levigroker/HashBuilder |
License | Creative Commons Attribution 3.0 Unported License |
Platforms | ios 5.0, osx 10.7, requires ARC |
Frameworks | Foundation |
Authors |
Used to build a hash result from contributed objects or hashes (presumably
properties on your object which should be considered in the isEqual: override).
The intention is for the hash result to be returned from an override to the
NSObject
- (NSUInteger)hash
method.
Installing
If you’re using CocoPods it’s as simple as adding this to your Podfile
:
pod 'HashBuilder', '~> 1.0'
otherwise, simply add the contents of the HashBuilder
subdirectory to your
project.
Documentation
To use, create a HashBuilder object, contribute to it, then query the ‘builtHash’
property for the resulting hash.
- (NSUInteger)hash
{
HashBuilder *builder = [HashBuilder builder];
[builder contributeObject:self.objectID];
[builder contributeObject:self.occurredDate];
[builder contributeObject:self.type];
[builder contributeObject:self.objectURL];
[builder contributeObject:self.tags];
[builder contributeObject:self.count];
NSUInteger retVal = builder.builtHash;
return retVal;
}
It is prudent to consider the same properties when overriding your - (BOOL)isEqual:(id)object
method as well.
NOTE: The order of contribution will change the resulting hash, even if all
the same values are contributed. For example:
HashBuilder *builder1 = [HashBuilder builder];
[builder1 contributeObject:@"a"];
[builder1 contributeObject:[NSNumber numberWithInteger:12345]];
NSUInteger hash1 = builder1.builtHash;
HashBuilder *builder2 = [HashBuilder builder];
[builder2 contributeObject:[NSNumber numberWithInteger:12345]];
[builder2 contributeObject:@"a"];
NSUInteger hash2 = builder2.builtHash;
hash1 != hash2
Disclaimer and Licence
- This work makes use of techniques and concepts presented by Mike Ash
in his post entitled Implementing Equality and Hashing - This work is licensed under the Creative Commons Attribution 3.0 Unported License.
Please see the included LICENSE.txt for complete details.
About
A professional iOS engineer by day, my name is Levi Brown. Authoring a technical
blog grokin.gs, I am reachable via:
Twitter @levigroker
EMail [email protected]
Your constructive comments and feedback are always welcome.
Latest podspec
{ "name": "HashBuilder", "version": "1.0.1", "summary": "A utility to generate a hash for NSObject subclasses.", "description": "Used to build a hash result from contributed objects or hashes (presumablynproperties on your object which should be considered in the isEqual: override).nThe intention is for the hash result to be returned from an override to then`NSObject` `- (NSUInteger)hash` method.", "homepage": "https://github.com/levigroker/HashBuilder", "license": "Creative Commons Attribution 3.0 Unported License", "authors": { "Levi Brown": "[email protected]" }, "social_media_url": "https://twitter.com/levigroker", "source": { "git": "https://github.com/levigroker/HashBuilder.git", "tag": "1.0.1" }, "platforms": { "ios": "5.0", "osx": "10.7" }, "source_files": "HashBuilder/**/*.{h,m}", "frameworks": "Foundation", "requires_arc": true }
Wed, 02 Mar 2016 06:41:03 +0000