0

I am trying to construct a library in IOS.

In my library ,I use a method -(void)loadNewData to load some data EX:test.csv.

But when I export my library and let the other app use my library to excute the loadNewData method. I found it can not be load correctly. It seems that because there is not such a file test.csv in the app.

How should I revise my code? Or where should I notice when I export the library?

Thank you for watch my question. And sorry for my poor English.

Here is the a part of code of the loadNewData:

NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *Rawsurveys=[resourcePath stringByAppendingPathComponent:@"test.csv"];
NSString *RawsurveyResults;
    if([[NSFileManager defaultManager]fileExistsAtPath:Rawsurveys])
    {
        NSLog(@"find file");
        NSFileHandle *RawfileHandle=[NSFileHandle fileHandleForReadingAtPath:Rawsurveys];
        RawsurveyResults=[[NSString alloc]initWithData:[RawfileHandle availableData] encoding:NSUTF8StringEncoding];
        [RawfileHandle closeFile];

    }

1 Answers1

0

You could probably create a bundle within your library and add you test.csv there. Then you can access your test.csv from your own bundle.

Example of how I use images from my bundle. [UIImage imageNamed:@"myBundle.bundle/myImage"]. You could use the somewhat same for your file

Ganesh Somani
  • 2,280
  • 2
  • 28
  • 37
  • Sorry,I can't understand what you mean. How to access my own bundle ? Can you give me some example code here? I will appreciate your help. :) – Hank Huang Feb 09 '15 at 02:54
  • You can have a look at https://github.com/hackiftekhar/IQKeyboardManager , check how there is a separate bundle for images made here and how how these images are accesses by the framework – Ganesh Somani Feb 09 '15 at 04:27
  • oh ya!! I just google "How to create a bundle" and study some documents there. Now I totally understand what you mean then I follow your steps and it works perfectly. Thank you for your help again :) . – Hank Huang Feb 09 '15 at 04:47