Our DNA is written in Swift

DTFoundation 1.5.2

This update for DTFoundation fixes issues with DTLog and DTHTMLParser and adds a few new utility methods.


  • ADDED: Method for duplicating template image tinting under iOS 6
  • ADDED: DTLog function for retrieving current app log messages
  • ADDED: DTLog function for duplicating NSLog but using ASL and specifying severity level
  • FIXED: DTLog issue when being called from C-function
  • FIXED: DTHTMLParser would not accumulate characters if no tag start and end delegate methods were set

The newly added method in UIImage+DTFoundation allows for creating tinted images from template images, similar to what will be happening in a future iOS version.

UIImage *buttonImage = [UIImage imageNamed:@"Button"];
UIImage tintedImage = [buttonImage imageMaskedAndTintedWithColor:[UIColor redColor]];

The issue in DTHTMLParser came to light when I was researching the fastest method for replacing HTML entities in a string. Turns out that DTHTMLParser is the fastest because it uses the highly optimized libxml2’s HTML parser. But to use it you need to instantiate it and take the result from parser:foundCharacters:. Before I fixed the above mentioned issue you would not get any result because this minimal example does not need the tag begin and end delegate methods.

@implementation AppDelegate
  NSString *_convertedString;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
	NSString *string = @"Some text & some entities";
	NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
	DTHTMLParser *parser = [[DTHTMLParser alloc] initWithData:data encoding:NSUTF8StringEncoding];
	parser.delegate = self;
	BOOL b = [parser parse];
	NSLog(@"converted %@", _convertedString);
  // ...
- (void)parser:(DTHTMLParser *)parser foundCharacters:(NSString *)string
	_convertedString = [string copy];

From my experiments with the new DTLog functionality, I also added a method to do the same as NSLog, but also be able to specify a log level. And there is now a method to retrieve the current app’s log messages. With that you could implement a user-facing feature to send the log messages to your support email address. The Apple System Log facility on iOS filters does display the least important two levels (info and debug), but does not store them in the log message database. Contrary to OS X there is no method to change this. So if you use info and debug messages you should probably not rely on ASL to keep them for you. Instead you would append them to a text file, possibly only if the user switches on debugging info in the app settings.

I made a change to the method name parameter so that it works both in an Objective-C method as well as a C-function. Turns out in both cases theĀ __PRETTY_FUNCTION__ macro gives us a nice context for our error messages. With this change you can use the DTLog* macros in both worlds with ease. Please refer to the DTLog introductory article to learn how to use that.

The update is tagged on GitHub on the master branch and also available via CocoaPods.

Tagged as:

Categories: Updates