When using solutions such as
there are several counters and side effects,
[NSBundle mainBundle]
or
NSBundle *localBundle = [NSBundle bundleForClass:[myObject class]]
when the structure of the application is similar to
MyContainerApp |------Frameworks/ |-----------------MyFramework.framwork/ |-------------------Resources/ |-------------mydata.json
So, if you can create a package file and transfer it to a container application (as a third-party framework developer), you can provide this API
+ (NSBundle *)frameworkBundle { static NSBundle* frameworkBundle = nil; static dispatch_once_t predicate; dispatch_once(&predicate, ^{ NSString* mainBundlePath = [[NSBundle mainBundle] resourcePath]; NSString* frameworkBundlePath = [mainBundlePath stringByAppendingPathComponent:@"YourFrameworkBundle.bundle"]; frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath]; }); return frameworkBundle; }
BUT very super-lightweight and let the super-efficient solution be the old C header with hexdump
xxd -i mydata.json >> mydata.json.h
This hexdump will generate a header file with these definitions.
unsigned char mydata_json[] = {
and
unsigned int mydata_json_len = 32227;
So in your structure or static library you can access it simply
unsigned char *rawBytes = mydata_json; NSUInteger dataLen = mydata_json_len; NSData *serializedData = [NSData dataWithBytesNoCopy:rawBytes length:dataLen freeWhenDone:NO];
then you might want to get it into text:
NSString* myString = [NSString stringWithUTF8String:[rawBytes bytes]];
What is it. Happy coding!