accessing a file using [NSBundle mainBundle] pathForResource: ofType:inDirectory:

前端 未结 10 1390
清酒与你
清酒与你 2020-12-02 07:56

I have a file paylines.txt added inside the folder named TextFiles which resides inside the Resources folder of my iOS project in Xcod

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 08:33

    Try this, it's working for me.

    NSString *str = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"paylines.txt"];  
    

    For simulator

    NSURL *rtfUrl = [[NSBundle mainBundle] URLForResource:@"paylines" withExtension:@".txt"];
    

提交回复
热议问题