views:

55

answers:

3

I have iPhone Library in c (it is created from c source in MAC). There is a method that read a file using file path. Now I want to input the file path in Objective-C to that method. My questions are:

  • Is it possible to do? I mean use c library to read file on iPhone.

if it is possible,

  • Where is the location in my project to put the file? (Resources ?)
  • And, how can I get the path to be input in the method? (NSBundle ?)

Thanks

A: 

Can't really answer you first question, cause I don't know the answer.

But for the second file, the best location is the documents directory. To get the path of a file:

NSString* myPath = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"plist"];

Or in a specific directory:

NSArray *myPathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *myDirectory = [myPathArray objectAtIndex:0];
    NSString *myPath = [myDirectory stringByAppendingPathComponent:@"myFile.plist"];

Hope that answered your question.

Regards, Paul Peelen

Paul Peelen
A: 

Yes, you can use static C libraries on the iPhone, unless they have dependencies that cannot be resolved. Objective-C is a superset of C, so you can just code in C and use your library this way and it will compile just fine.

Pascal
A: 

Thanks for ur response.

I finally did it using both NSBundle and temp directory.

Nirvash