无法在swift 2.1中读取plist文件

时间:2023-01-24 08:25:54

I am trying to read the plist file i have created. I am able to read the Info.plist file, but when i try to read newly created file it give's me nil value for the path. Below is the code i am using

我正在尝试阅读我创建的plist文件。我能够读取Info.plist文件,但是当我尝试读取新创建的文件时,它给出了路径的零值。以下是我正在使用的代码

let path = NSBundle.mainBundle().pathForResource("Config1", ofType: "plist")
    if let dict = NSDictionary(contentsOfFile: path!) {

        print("Plist:\(dict)")

    }

1 个解决方案

#1


0  

Check Your Plist file path , it must be in the same folder where your info.plist file , you can check it by

检查您的Plist文件路径,它必须与您的info.plist文件位于同一文件夹中,您可以查看它

  • go to your Project folder and copy your plist file to the root of your project folder
  • 转到Project文件夹并将plist文件复制到项目文件夹的根目录

  • make two copy of your plist file one in the root folder and other in sub-folder
  • 在根文件夹中制作一个plist文件的副本,在子文件夹中制作另一个副本

try to run your app , if not nil try to find out what is the correct path

尝试运行你的应用程序,如果不是零尝试找出什么是正确的路径

#1


0  

Check Your Plist file path , it must be in the same folder where your info.plist file , you can check it by

检查您的Plist文件路径,它必须与您的info.plist文件位于同一文件夹中,您可以查看它

  • go to your Project folder and copy your plist file to the root of your project folder
  • 转到Project文件夹并将plist文件复制到项目文件夹的根目录

  • make two copy of your plist file one in the root folder and other in sub-folder
  • 在根文件夹中制作一个plist文件的副本,在子文件夹中制作另一个副本

try to run your app , if not nil try to find out what is the correct path

尝试运行你的应用程序,如果不是零尝试找出什么是正确的路径