Skip to content

Instantly share code, notes, and snippets.

@augard
Created February 19, 2014 12:42
Show Gist options
  • Save augard/9091199 to your computer and use it in GitHub Desktop.
Save augard/9091199 to your computer and use it in GitHub Desktop.
// DNSSDService implements -isEqual: based on a comparison of the domain, type and name, and
// it implements -hash correspondingly. This allows you to use DNSSDService objects in sets,
// as dictionary keys, and so on.
//
// IMPORTANT: This uses case-sensitive comparison. In general DNS is case insensitive.
// DNS-SD will always pass you services with a consistent case, so using case sensitive
// comparison here is not a problem. You might run into problems, however, if you do
// odd things like manually create a DNSSDService with the domain set to "LOCAL." instead
// of "local.".
//
// DNSSDService also implements NSCopying. When you copy a service, the copy has the same
// domain, type and name as the original. However, the copy does not bring across any of
// the resolution state. Specifically:
//
// o If the original was resolving, the copy is not.
//
// o If the original had successfully resolved (and thus has resolvedHost and resolvedPort set),
// these results are not present in the copy.
//
// However, because the domain, type and name are copied, and these are the only things
// considered by -isEqual: and -hash, DNSSDService can be used as a dictionary key.
- (BOOL)isEqual:(id)object
{
DNSSDService *other;
// Boilerplate stuff.
if (object == self) {
return YES;
}
if (![object isKindOfClass:[self class]] ) {
return NO;
}
// Compare the domain, type and name.
other = (DNSSDService *)object;
return [self.domain isEqualToString:other.domain] && [self.type isEqualToString:other.type] && [self.name isEqualToString:other.name];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment