Permalink
Browse files

Improved error reporting on loading gestures.

  • Loading branch information...
1 parent d0926dd commit 7270889d093b098e20d341563c95f26c4450b742 @preble committed Oct 15, 2012
@@ -12,6 +12,6 @@
@interface GLGestureRecognizer (JSONTemplates)
-- (BOOL)loadTemplatesFromJsonData:(NSData *)jsonData;
+- (BOOL)loadTemplatesFromJsonData:(NSData *)jsonData error:(NSError **)errorOut;
@end
@@ -10,15 +10,17 @@
@implementation GLGestureRecognizer (JSONTemplates)
-- (BOOL)loadTemplatesFromJsonData:(NSData *)jsonData
+- (BOOL)loadTemplatesFromJsonData:(NSData *)jsonData error:(NSError **)errorOut
{
// The recognized gestures are loaded from JSON format, using the TouchJSON library.
// As an example, if kSamplePoints were 3, here is an example file with one gesture:
// { "line" : [ [1.0, 0.0], [0.0, 0.0], [-1.0, 0.0] ] }
// (A dictionary with string key names and an array of 2-element array coordinate pairs.)
// To populate the file, use the output of the NSLog()s in findBestMatch..: after drawing a shape.
- NSError *error = nil;
- NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
+ NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:errorOut];
+ if (!dict)
+ return NO;
+
NSMutableDictionary *output = [NSMutableDictionary dictionary];
[dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSArray *value, BOOL *stop) {
NSMutableArray *points = [NSMutableArray arrayWithCapacity:value.count];
View
@@ -35,7 +35,16 @@ - (void)awakeFromNib
{
recognizer = [[GLGestureRecognizer alloc] init];
NSData *jsonData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Gestures" ofType:@"json"]];
- [recognizer loadTemplatesFromJsonData:jsonData];
+
+ BOOL ok;
+ NSError *error;
+ ok = [recognizer loadTemplatesFromJsonData:jsonData error:&error];
+ if (!ok)
+ {
+ NSLog(@"Error loading gestures: %@", error);
+ self.caption = @"Error loading gestures.";
+ return;
+ }
self.caption = @"";
}

0 comments on commit 7270889

Please sign in to comment.