Created
May 21, 2015 16:32
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <UIKit/UIKit.h> | |
@interface JSONFromBundle : NSObject | |
// Also removes nulls | |
+ (id)nameNoExtension:(NSString *)name; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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