4

I have a value inside of my info.plist called radiusDistance that i'm trying to change, i've attempted using this code but it doesn't change the value

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)")
    }

Everything runs but when I go back to my info.plist nothing changes, and the value remains at "0"

notJenny
  • 185
  • 1
  • 2
  • 11
  • You should load your plist the first time your app launches and save it somewhere locally. After that you can do whatever you want to your property list file – Leo Dabus Apr 16 '17 at 02:40

1 Answers1

6

An app's bundle is read-only. You can't save changes to your bundle.

EDIT:

And, as "Alexander" says, you should not try to make a program self-modifying. That's bad coding practice, even if it was possible.

Duncan C
  • 128,072
  • 22
  • 173
  • 272