Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded resources in Objective C?

I have a library in both C# and Java that use some XML files to generate a lot of objects. I use them so I don't have to hardcode it in both languages, and can easily update the data.

In both C# and Java I can embed these files into the DLL/Package.

How would I proceed to do something like this in Objective-C?

like image 414
Peterdk Avatar asked Aug 29 '26 11:08

Peterdk


1 Answers

This isn't a language level question, it's a platform packaging level question. On both Mac OS X and iOS, typically you'll add the resource file to your project, then get the path to the file from NSBundle:

NSString *path = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"xml"];

Libraries in Objective-C are called frameworks. Like applications, they are also bundles on Mac OS X and instead of mainBundle you probably want to use bundleForClass:.

iOS does not support frameworks, only static libraries, so you won't be able to include your resource files with your library on that platform. They must be added directly to the project.

like image 61
Steve Madsen Avatar answered Aug 31 '26 02:08

Steve Madsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!