pEpObjCAdapter/NSDictionary+Debug.m
author Dirk Zimmermann <dirk@pep-project.org>
Thu, 07 Jun 2018 11:12:18 +0200
changeset 623 fade443297e3
parent 622 5c5d267a32a0
child 851 e62e76f93075
permissions -rw-r--r--
IOS-559 better NSDictionary.dumpReferences
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
dirk@622
    11
#import "PEPMessageUtil.h"
dirk@622
    12
dirk@622
    13
@implementation NSDictionary (Debug)
dirk@622
    14
dirk@622
    15
- (void)debugSaveToFilePath:(NSString * _Nonnull)filePath
dirk@622
    16
{
dirk@622
    17
    NSFileManager *fileManager = [NSFileManager defaultManager];
dirk@622
    18
    NSURL *parentPath = [[fileManager
dirk@622
    19
                          URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask]
dirk@622
    20
                         firstObject];
dirk@622
    21
dirk@622
    22
    NSDate *now = [NSDate date];
dirk@622
    23
    NSString *nowDesc = [now description];
dirk@622
    24
    NSString *fileName = [NSString stringWithFormat:@"%@_%@.%@",
dirk@622
    25
                          filePath, nowDesc, @"plist"];
dirk@622
    26
dirk@622
    27
    NSURL *writeURL = [NSURL fileURLWithPath:fileName relativeToURL:parentPath];
dirk@622
    28
    NSLog(@"debugSaveToFilePath: writing %@", writeURL);
dirk@622
    29
    [self writeToURL:writeURL atomically:YES];
dirk@622
    30
}
dirk@622
    31
dirk@623
    32
- (void)dumpReferences
dirk@623
    33
{
dirk@623
    34
    NSString *messageID = [self valueForKey:kPepID];
dirk@623
    35
    if (messageID == nil) {
dirk@623
    36
        messageID = @"unknown";
dirk@623
    37
    }
dirk@623
    38
    NSArray *references = [self valueForKey:kPepReferences];
dirk@623
    39
    if (references.count > 0) {
dirk@623
    40
        for (NSString *ref in references) {
dirk@623
    41
            NSLog(@"messageID %@ -> ref %@\n", messageID, ref);
dirk@623
    42
        }
dirk@623
    43
    } else {
dirk@623
    44
        NSLog(@"messageID %@ -> no refs\n", messageID);
dirk@623
    45
    }
dirk@623
    46
}
dirk@623
    47
dirk@622
    48
@end