NSData dataWithContentsOfFile returning null

前端 未结 6 1001
再見小時候
再見小時候 2021-02-19 11:19

I am trying to fetching a JSON file which exist in my xcode resources using this code

-(void)readJsonFiles
{
    NSString *str=[[[NSBu         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 11:50

    There is the solution for Swift 3 :

    //create a fil's path, decompose name and extension
    let path = Bundle.main.path(forResource: "anim-gif-1", ofType: "gif")
    //get the data asociated to this file
    let file = NSData(contentsOfFile: path!)
    

提交回复
热议问题