Skip to content

Commit

Permalink
Improved error reporting on loading gestures.
Browse files Browse the repository at this point in the history
  • Loading branch information
preble committed Oct 15, 2012
1 parent d0926dd commit 7270889
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion GLGestureRecognizer/GLGestureRecognizer+JSONTemplates.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

@interface GLGestureRecognizer (JSONTemplates)

- (BOOL)loadTemplatesFromJsonData:(NSData *)jsonData;
- (BOOL)loadTemplatesFromJsonData:(NSData *)jsonData error:(NSError **)errorOut;

@end
8 changes: 5 additions & 3 deletions GLGestureRecognizer/GLGestureRecognizer+JSONTemplates.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
11 changes: 10 additions & 1 deletion GesturesDemo/GestureView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @"";
}
Expand Down

0 comments on commit 7270889

Please sign in to comment.