2

I want to change/modify some value in info.plist from Swift programmatically. For example I want to change "NSAllowsArbitaryLoads" to 0. This is code what I am using for editing the value:

func editPlist(){
    var infoPlistPath = Bundle.main.path(forResource: "Info", ofType: "plist")

    var infoPlistDict = NSMutableDictionary(contentsOfFile: playersDictionaryPath!)

    var nsAppKey = infoPlistDict?.object(forKey: "NSAppTransportSecurity") as! NSDictionary

    print(nsAppKey["NSAllowsArbitraryLoads"])
    nsAppKey["NSAllowsArbitraryLoads"] = 0
}

In reality I want to change my exported UTIs image in Swift programmatically. I want to change it for each object that I want to share via UIActivityController.

P.S. : I am using Swift 3 in Xcode 8.

6
  • The Info.plist is – like all files in the application bundle – read only. You cannot modify it at runtime.
    – Martin R
    Oct 24, 2016 at 9:15
  • You can't modify a file inside your bundle. You have to make a copy to it and write it elsewhere. In our case, you won't be able to modify Info.plist at runtime.
    – Larme
    Oct 24, 2016 at 9:16
  • @MartinR Thank you. But how can I change my exported UTIs image from Swift? I think It's just accessible from Info.plist file. So I need to modify it and because of it I ask the question. So is there anyway to change exported UTIs image dynamically?
    – Behdad
    Oct 24, 2016 at 9:19
  • @Larme Thank you. Is there anyway to change exported UTIs image dynamically?
    – Behdad
    Oct 24, 2016 at 9:20
  • I am fairly sure that you can't. Also confirmed here: stackoverflow.com/questions/9116552/….
    – Martin R
    Oct 24, 2016 at 9:21

0

Browse other questions tagged or ask your own question.