Skip to content

Commit

Permalink
Merge pull request #4 from Patrick-Kladek/xcode11
Browse files Browse the repository at this point in the history
Carthage Support
  • Loading branch information
Patrick-Kladek authored May 22, 2020
2 parents 760bac3 + c82c6d6 commit 7618437
Show file tree
Hide file tree
Showing 86 changed files with 2,803 additions and 3,178 deletions.
53 changes: 18 additions & 35 deletions CocoaDebugKit.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CD2761EA1B0E1C050000BB5D"
BuildableName = "CocoaDebugKit.framework"
BlueprintName = "CocoaDebugKit"
ReferencedContainer = "container:CocoaDebugKit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CD2761EA1B0E1C050000BB5D"
BuildableName = "CocoaDebugKit.framework"
BlueprintName = "CocoaDebugKit"
ReferencedContainer = "container:CocoaDebugKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
@property (nonatomic) BOOL save;
@property (nonatomic) NSURL *saveUrl;


+ (CocoaDebugDescription *)debugDescription;
+ (CocoaDebugDescription *)debugDescriptionForObject:(NSObject *)obj;

Expand All @@ -31,10 +30,3 @@
- (BOOL)saveDebugDescriptionToUrl:(NSURL *)url error:(NSError **)error;

@end







170 changes: 170 additions & 0 deletions CocoaDebugKit/CocoaDebugKit/CocoaDebugDescription.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
//
// CocoaDebugDescription.m
// CocoaDebugKit
//
// Created by Patrick Kladek on 19.04.16.
// Copyright (c) 2016 Patrick Kladek. All rights reserved.
//

#import "CocoaDebugDescription.h"
#import "CocoaPropertyEnumerator.h"
#import "CocoaDebugSettings.h"
#import "NSObject+CPAdditions.h"


@interface CocoaDebugDescription ()

@property (nonatomic) CocoaPropertyEnumerator *propertyEnumerator;
@property (nonatomic) NSMutableArray *lines;
@property (nonatomic) NSInteger typeLenght;

@end


@implementation CocoaDebugDescription

+ (CocoaDebugDescription *)debugDescription
{
CocoaDebugDescription *description = [[self alloc] init];
return description;
}

+ (CocoaDebugDescription *)debugDescriptionForObject:(NSObject *)obj
{
CocoaDebugDescription *description = [[self alloc] init];
[description addAllPropertiesFromObject:obj];
return description;
}

- (instancetype)init
{
self = [super init];
if (self) {
_propertyEnumerator = [[CocoaPropertyEnumerator alloc] init];
_lines = [NSMutableArray array];
_typeLenght = 0;

CocoaDebugSettings *settings = [CocoaDebugSettings sharedSettings];

self.dataMaxLenght = settings.maxDataLenght;
self.save = settings.save;
self.saveUrl = settings.saveUrl;
}
return self;
}

- (void)addAllPropertiesFromObject:(NSObject *)obj
{
_obj = obj;

Class currentClass = [obj class];

while (currentClass != nil && currentClass != [NSObject class]) {
[self.propertyEnumerator enumeratePropertiesFromClass:currentClass
allowed:nil
block:^(NSString *type, NSString *name) {
[self addProperty:name type:type fromObject:obj];
}];

currentClass = [currentClass superclass];
}
}

- (void)addProperty:(NSString *)name type:(NSString *)type fromObject:(NSObject *)obj
{
if (!_obj) {
_obj = obj;
}


Class class = NSClassFromString(type);

if ([class isSubclassOfClass:[NSData class]]) {
NSData *data = [obj valueForKey:name];

// cut lenght to 100 byte
if ([data length] > self.dataMaxLenght.integerValue) {
data = [data subdataWithRange:NSMakeRange(0, self.dataMaxLenght.integerValue)];
}

[self addDescriptionLine:[CocoaPropertyLine lineWithType:type name:name value:[data description]]];
return;
}

if ([class isSubclassOfClass:[CPImage class]]) {
CPImage *image = [obj valueForKey:name];
NSString *imageDescription = [NSString stringWithFormat:@"size: %.0fx%.0f", image.size.width, image.size.height];
[self addDescriptionLine:[CocoaPropertyLine lineWithType:type name:name value:imageDescription]];
return;
}


id value = [obj valueForKey:name];
NSString *description = [[value description] stringByReplacingOccurrencesOfString:@"\n" withString:[NSString stringWithFormat:@"\n%@", [self _spaceFromLenght:4]]];
[self addDescriptionLine:[CocoaPropertyLine lineWithType:type name:name value:description]];
}

- (NSString *)stringRepresentation
{
NSMutableString *string = [NSMutableString stringWithFormat:@"<%p> %@ {\n", _obj, _obj.cp_className];
for (CocoaPropertyLine *line in self.lines) {
NSInteger deltaLenght = self.typeLenght - (line.type.length + line.name.length);
[string appendFormat:@"\t%@%@ %@ = %@\n", line.type, [self _spaceFromLenght:deltaLenght], line.name, line.value];
}

[string appendString:@"}"];
return string;
}

- (void)saveDebugDescription
{
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *appVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];// example: 1.0.0
NSString *buildNumber = [infoDict objectForKey:@"CFBundleVersion"];// example: 42

NSURL *url = [_saveUrl URLByAppendingPathComponent:appVersion];
url = [url URLByAppendingPathComponent:buildNumber];

NSError *error;
if (![[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:&error]) {
NSLog(@"%@", error);
return;
}

NSString *className = [_obj cp_className];

NSDictionary *debuggedObjects = [[CocoaDebugSettings sharedSettings] debuggedObjects];
NSInteger debuggedCount = [[debuggedObjects valueForKey:className] integerValue];
debuggedCount++;
[debuggedObjects setValue:[NSNumber numberWithInteger:debuggedCount] forKey:className];
url = [url URLByAppendingPathComponent:[NSString stringWithFormat:@"%@ %li.txt", className, (long) debuggedCount]];

[self saveDebugDescriptionToUrl:url error:nil];
}

- (BOOL)saveDebugDescriptionToUrl:(NSURL *)url error:(NSError **)error
{
return [[self stringRepresentation] writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:error];
}

#pragma mark - Private

- (NSString *)_spaceFromLenght:(NSInteger)lenght
{
NSMutableString *string = [[NSMutableString alloc] initWithCapacity:lenght];
for (NSInteger i = 0; i < lenght; i++) {
[string appendString:@" "];
}
return string;
}

- (void)addDescriptionLine:(CocoaPropertyLine *)line
{
if (line.type.length + line.name.length > self.typeLenght) {
self.typeLenght = line.type.length + line.name.length;
}

[self.lines addObject:line];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
// Copyright (c) 2015 Patrick Kladek. All rights reserved.
//

#include <TargetConditionals.h>

#if TARGET_OS_IPHONE
// iOS code
@import UIKit;
#else
#import <Cocoa/Cocoa.h>
@import AppKit;
#endif


//! Project version number for CocoaDebugKit.
FOUNDATION_EXPORT double CocoaDebugFrameworkVersionNumber;

Expand Down
Loading

0 comments on commit 7618437

Please sign in to comment.