Skip to content

Instantly share code, notes, and snippets.

@benvium
Created May 21, 2015 16:32
Show Gist options
  • Save benvium/91b69c4554a61b68082c to your computer and use it in GitHub Desktop.
Save benvium/91b69c4554a61b68082c to your computer and use it in GitHub Desktop.
Simple class to read a json file from the bundle. Works in unit tests or a 'real' app.
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface JSONFromBundle : NSObject
// Also removes nulls
+ (id)nameNoExtension:(NSString *)name;
@end
#import "JSONFromBundle.h"
@implementation JSONFromBundle
+ (id)nameNoExtension:(NSString *)name {
NSMutableDictionary *result = [NSJSONSerialization
JSONObjectWithData:
[NSData dataWithContentsOfFile:
[[NSBundle bundleForClass:[self class]] pathForResource:name
ofType:@"json"]
options:0
error:nil]
options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves
error:nil];
return result;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment