forked from nygard/class-dump
-
Notifications
You must be signed in to change notification settings - Fork 241
/
CDXibStoryBoardProcessor.m
43 lines (35 loc) · 1.46 KB
/
CDXibStoryBoardProcessor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#import "CDXibStoryBoardProcessor.h"
#import "CDXibStoryboardParser.h"
@implementation CDXibStoryBoardProcessor
- (void)obfuscateFilesUsingSymbols:(NSDictionary *)symbols {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *keys = @[NSURLIsDirectoryKey];
NSURL *directoryURL;
if (self.xibBaseDirectory) {
directoryURL = [NSURL URLWithString:self.xibBaseDirectory];
} else {
directoryURL = [NSURL URLWithString:@"."];
}
NSDirectoryEnumerator *enumerator = [fileManager
enumeratorAtURL:directoryURL
includingPropertiesForKeys:keys
options:0
errorHandler:^(NSURL *url, NSError *error) {
// Handle the error.
// Return YES if the enumeration should continue after the error.
return YES;
}];
CDXibStoryboardParser *parser = [[CDXibStoryboardParser alloc] init];
for (NSURL *url in enumerator) {
NSError *error;
NSNumber *isDirectory = nil;
if ([url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error] && ![isDirectory boolValue]) {
if ([url.absoluteString hasSuffix:@".xib"] || [url.absoluteString hasSuffix:@".storyboard"]) {
NSLog(@"Obfuscating IB file at path %@", url);
NSData *data = [parser obfuscatedXmlData:[NSData dataWithContentsOfURL:url] symbols:symbols];
[data writeToURL:url atomically:YES];
}
}
}
}
@end