以编程方式更新info.plist中的值

时间:2017-04-16 02:28:26

标签: ios swift plist info.plist

我的info.plist中有一个名为radiusDistance的值,我正在尝试更改,我尝试使用此代码,但它不会更改值

let path = Bundle.main.path(forResource: "Info", ofType: "plist")!
    var dict = NSDictionary(contentsOfFile: path) as! [String: AnyObject]


    let radiusDistance = dict["radiusDistance"]
    print("radiusDistance",radiusDistance as Any)
    let value = Int(5)


    do{
         dict.updateValue(value as AnyObject, forKey: "radiusDistance")
     try path.write(toFile: path, atomically: false, encoding:String.Encoding.utf8)
    }
    catch let error as NSError{
        print("something went horribly wrong\(error.debugDescription)")
    }

一切都在运行但是当我回到我的info.plist时没有任何变化,值仍为“0”

1 个答案:

答案 0 :(得分:4)

应用程序包是只读的。您无法保存对捆绑包的更改。