IOSAD-91 PEPAttachment.initWithData
authorDirk Zimmermann <dirk@pep-project.org>
Mon, 16 Apr 2018 11:01:23 +0200
changeset 5810954976b8da9
parent 580 0a0ba4c4ba91
child 582 768d3beffeb8
child 586 db770f2c669b
IOSAD-91 PEPAttachment.initWithData
pEpObjCAdapter/PEPAttachment.h
pEpObjCAdapter/PEPAttachment.m
pEpObjCAdapter/PEPMessageUtil.m
pEpObjCTests/TestUtils/PEPTestUtils.m
     1.1 --- a/pEpObjCAdapter/PEPAttachment.h	Mon Apr 16 11:01:22 2018 +0200
     1.2 +++ b/pEpObjCAdapter/PEPAttachment.h	Mon Apr 16 11:01:23 2018 +0200
     1.3 @@ -18,4 +18,6 @@
     1.4  @property (nonatomic, nullable) NSString *filename;
     1.5  @property (nonatomic) content_disposition_type contentDisposition;
     1.6  
     1.7 +- (_Nonnull instancetype)initWithData:(NSData *)data;
     1.8 +
     1.9  @end
     2.1 --- a/pEpObjCAdapter/PEPAttachment.m	Mon Apr 16 11:01:22 2018 +0200
     2.2 +++ b/pEpObjCAdapter/PEPAttachment.m	Mon Apr 16 11:01:23 2018 +0200
     2.3 @@ -10,4 +10,12 @@
     2.4  
     2.5  @implementation PEPAttachment
     2.6  
     2.7 +- (instancetype)initWithData:(NSData *)data
     2.8 +{
     2.9 +    if (self = [super init]) {
    2.10 +        self.data = data;
    2.11 +    }
    2.12 +    return self;
    2.13 +}
    2.14 +
    2.15  @end
     3.1 --- a/pEpObjCAdapter/PEPMessageUtil.m	Mon Apr 16 11:01:22 2018 +0200
     3.2 +++ b/pEpObjCAdapter/PEPMessageUtil.m	Mon Apr 16 11:01:23 2018 +0200
     3.3 @@ -131,8 +131,9 @@
     3.4      NSMutableArray *array = [NSMutableArray array];
     3.5      
     3.6      for (bloblist_t *_bl = bl; _bl && _bl->value; _bl = _bl->next) {
     3.7 -        PEPAttachment* theAttachment = [PEPAttachment new];
     3.8 -        theAttachment.data = [NSData dataWithBytes:_bl->value length:_bl->size];
     3.9 +        PEPAttachment* theAttachment = [[PEPAttachment alloc]
    3.10 +                                        initWithData:[NSData
    3.11 +                                                      dataWithBytes:_bl->value length:_bl->size]];
    3.12  
    3.13          if(_bl->filename && _bl->filename[0]) {
    3.14              theAttachment.filename = [NSString stringWithUTF8String:_bl->filename];
     4.1 --- a/pEpObjCTests/TestUtils/PEPTestUtils.m	Mon Apr 16 11:01:22 2018 +0200
     4.2 +++ b/pEpObjCTests/TestUtils/PEPTestUtils.m	Mon Apr 16 11:01:23 2018 +0200
     4.3 @@ -76,8 +76,8 @@
     4.4  {
     4.5      NSMutableArray *attachments = [NSMutableArray new];
     4.6      for (NSDictionary *attachmentDict in [message objectForKey:kPepAttachments]) {
     4.7 -        PEPAttachment *attachment = [PEPAttachment new];
     4.8 -        attachment.data = [attachmentDict objectForKey:@"data"];
     4.9 +        PEPAttachment *attachment = [[PEPAttachment alloc]
    4.10 +                                     initWithData:[attachmentDict objectForKey:@"data"]];
    4.11          attachment.filename = [attachmentDict objectForKey:@"filename"];
    4.12          attachment.mimeType = [attachmentDict objectForKey:@"mimeType"];
    4.13          [attachments addObject:attachment];