Skip to content

maxsz/debuggify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Debug Macros for Objective-C

Debuggify is a collection of shortcut macros for quickly adding debugging output to Objective-C methods. See below for examples.

How to get started

Just add the debuggify.h header to your project (for example #import "debuggify.h" in your project's .pch) and set the DEBUG flag.

Examples

Here's a couple of simple examples to give an idea of how debuggify works:

Just add the @debuggify() macro at the beginning of the method you want to debug and pass it any interesting objects you want to log. Optionally add @debuggify_time at the end to print the time it took to execute the method.

@interface SomeClass
@property NSString *someState;
@end

@implementation SomeClass
- (id)init
{
  self = [super init];
  if (self) {
    self.someState = @"I'm doing something..."
  }
  return self;
}

- (void)doSomethingWith:(SomeClass *)someone
{
  @debuggify(self, someone)

  sleep(10); // d`oh

  @debuggify_time
}

- (NSString *)description
{
  return self.someState;
}
@end

Now running this code...

SomeClass *sc = [SomeClass new];
sc.someState = @"I'm doing something else!";
[[SomeClass new] doSomethingWith:sc];

...will print the following message:

> -[SomeClass doSomethingWith:]:
>      0: self = I'm doing something...
>      1: someone = I'm doing something else!
> Execution time: 10.001630ms

Logging

Debuggify includes some very basic logging functions for replacing the standard NSLog.

MXLogEmergency(...)
MXLogAlert(...)
MXLogCritical(...)
MXLogError(...)
MXLogWarning(...)
MXLogNotice(...)
MXLogInfo(...)
MXLogDebug(...)

The default (compile-time) log level is set to notice for non-debug builds and to the highest level (debug) for debug builds.

Contributions

Pull requests are very welcome. It would be nice to make this thing more advanced. One particular thing would be to add support for method paramters. There is already a lot of code out there that does this, but I wanted to keep this short and without any compiled code (i.e. just a header to drop in).

Issues

Please report any issues to the GitHub issuetracker.

Thanks

Thank you to Jake Wharton for the inspiration by creating something similiar (but way more advanced) for Java. I would also like to thank Justin Spahr-Summers for creating the awesome libextobjc from which I am using the macros for metaprogramming. Thanks to David Beck for creating TULogging, which is used (with some modifications) for the debuggify logging facilities.

About

Simple debugging macros for Objective-C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages