IOSAD-92 PEPMessage.isEqual with `[nil isEqual:nil] == YES` IOSAD-92
authorDirk Zimmermann <dirk@pep-project.org>
Tue, 24 Apr 2018 13:29:16 +0200
branchIOSAD-92
changeset 5916f43608139c8
parent 590 5cf796a94b87
child 592 95dde8be4786
IOSAD-92 PEPMessage.isEqual with `[nil isEqual:nil] == YES`
pEpObjCAdapter/PEPMessage.m
     1.1 --- a/pEpObjCAdapter/PEPMessage.m	Tue Apr 24 13:29:15 2018 +0200
     1.2 +++ b/pEpObjCAdapter/PEPMessage.m	Tue Apr 24 13:29:16 2018 +0200
     1.3 @@ -240,24 +240,40 @@
     1.4  
     1.5  - (BOOL)isEqualToPEPMessage:(PEPMessage * _Nonnull)message
     1.6  {
     1.7 -    return [self.attachments isEqualToArray:message.attachments] &&
     1.8 -    [self.bcc isEqualToArray:message.bcc] &&
     1.9 -    [self.cc isEqualToArray:message.cc] &&
    1.10 -    self.direction == message.direction &&
    1.11 -    [self.from isEqual:message.from] &&
    1.12 -    [self.inReplyTo isEqualToArray:message.inReplyTo] &&
    1.13 -    [self.keywords isEqualToArray:message.keywords] &&
    1.14 -    [self.longMessage isEqualToString:message.longMessage] &&
    1.15 -    [self.longMessageFormatted isEqualToString:message.longMessageFormatted] &&
    1.16 -    [self.messageID isEqualToString:message.messageID] &&
    1.17 -    [self.optionalFields isEqualToArray:message.optionalFields] &&
    1.18 -    [self.receivedBy isEqual:message.receivedBy] &&
    1.19 -    [self.receivedDate isEqual:message.receivedDate] &&
    1.20 -    [self.references isEqualToArray:message.references] &&
    1.21 -    [self.replyTo isEqualToArray:message.replyTo] &&
    1.22 -    [self.sentDate isEqual:message.sentDate] &&
    1.23 -    [self.shortMessage isEqualToString:message.shortMessage] &&
    1.24 -    [self.to isEqual:message.to];
    1.25 +    NSArray *keys = @[
    1.26 +                      @"attachments",
    1.27 +                      @"bcc",
    1.28 +                      @"cc",
    1.29 +                      @"direction",
    1.30 +                      @"from",
    1.31 +                      @"inReplyTo",
    1.32 +                      @"keywords",
    1.33 +                      @"longMessage",
    1.34 +                      @"longMessageFormatted",
    1.35 +                      @"messageID",
    1.36 +                      @"optionalFields",
    1.37 +                      @"receivedBy",
    1.38 +                      @"receivedDate",
    1.39 +                      @"references",
    1.40 +                      @"replyTo",
    1.41 +                      @"sentDate",
    1.42 +                      @"shortMessage",
    1.43 +                      @"to",
    1.44 +                      ];
    1.45 +
    1.46 +    for (NSString *theKey in keys) {
    1.47 +        NSObject *objSelf = [self objectForKey:theKey];
    1.48 +        NSObject *objOther = [message objectForKey:theKey];
    1.49 +
    1.50 +        if (objSelf == nil && objOther == nil) {
    1.51 +            // considered equal, continue
    1.52 +        } else if (![objSelf isEqual:objOther]) {
    1.53 +            // NSValue, NSArray, NSString all have correctly implemented isEqual, so this works
    1.54 +            return NO;
    1.55 +        }
    1.56 +    }
    1.57 +
    1.58 +    return YES;
    1.59  }
    1.60  
    1.61  - (NSUInteger)hash