pEpObjCAdapter/NSDictionary+Debug.m
author Dirk Zimmermann <dz@pep.security>
Wed, 20 Mar 2019 16:40:35 +0100
branchIOS-1480
changeset 902 32760267cd59
parent 851 e62e76f93075
permissions -rw-r--r--
IOS-1480 Avoid framework imports.
dirk@622
     1
//
dirk@622
     2
//  NSDictionary+Debug.m
dirk@622
     3
//  pEpObjCAdapter
dirk@622
     4
//
dirk@622
     5
//  Created by Dirk Zimmermann on 07.06.18.
dirk@622
     6
//  Copyright © 2018 p≡p. All rights reserved.
dirk@622
     7
//
dirk@622
     8
dirk@622
     9
#import "NSDictionary+Debug.h"
dirk@622
    10
dz@902
    11
#import "PEPConstants.h"
dz@851
    12
dirk@622
    13
#import "PEPMessageUtil.h"
dirk@622
    14
dirk@622
    15
@implementation NSDictionary (Debug)
dirk@622
    16
dirk@622
    17
- (void)debugSaveToFilePath:(NSString * _Nonnull)filePath
dirk@622
    18
{
dirk@622
    19
    NSFileManager *fileManager = [NSFileManager defaultManager];
dirk@622
    20
    NSURL *parentPath = [[fileManager
dirk@622
    21
                          URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask]
dirk@622
    22
                         firstObject];
dirk@622
    23
dirk@622
    24
    NSDate *now = [NSDate date];
dirk@622
    25
    NSString *nowDesc = [now description];
dirk@622
    26
    NSString *fileName = [NSString stringWithFormat:@"%@_%@.%@",
dirk@622
    27
                          filePath, nowDesc, @"plist"];
dirk@622
    28
dirk@622
    29
    NSURL *writeURL = [NSURL fileURLWithPath:fileName relativeToURL:parentPath];
dirk@622
    30
    NSLog(@"debugSaveToFilePath: writing %@", writeURL);
dirk@622
    31
    [self writeToURL:writeURL atomically:YES];
dirk@622
    32
}
dirk@622
    33
dirk@623
    34
- (void)dumpReferences
dirk@623
    35
{
dirk@623
    36
    NSString *messageID = [self valueForKey:kPepID];
dirk@623
    37
    if (messageID == nil) {
dirk@623
    38
        messageID = @"unknown";
dirk@623
    39
    }
dirk@623
    40
    NSArray *references = [self valueForKey:kPepReferences];
dirk@623
    41
    if (references.count > 0) {
dirk@623
    42
        for (NSString *ref in references) {
dirk@623
    43
            NSLog(@"messageID %@ -> ref %@\n", messageID, ref);
dirk@623
    44
        }
dirk@623
    45
    } else {
dirk@623
    46
        NSLog(@"messageID %@ -> no refs\n", messageID);
dirk@623
    47
    }
dirk@623
    48
}
dirk@623
    49
dirk@622
    50
@end