NSBundle pathForResource is NULL

前端 未结 9 1004
感情败类
感情败类 2020-11-29 04:41

I\'m creating a simple application with xcode and objc and I need to load an NSDictionary from a file, but I can\'t get the path to the file using NSBundle:

         


        
9条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 05:05

    Since I have googled here, did not find the answer, but then discovered it by myself, I'll leave it here...

    I had 2 files: tray.png and tray@2x.png for Retina. The files were added to "Copy Bundle Resources" automatically.

    But:

    [[NSBundle mainBundle] pathForResource:@"tray" ofType:@"png"];
    

    did not return the file actually copied to the bundle! The reason was: IDE created one TIFF file tray.tiff (joint tray.png and tray@2x.png), so ... ofType:@"tiff"] helped!

提交回复
热议问题