mimi93 mimi93 - 4 months ago 9
Swift Question

Plist not changing value [swift]

I wanted to implement the in-app version for my app, but I don't understand why is not working? The output showing i was added successfully, but when i open the pList file from my Xcode, its not changing? Why is it? Here is my code:

func version(){

let urlString = jocomAPIKey + "/feed/version"
let CFBundleShortVersionKey = "CFBundleVersion"

//First get the nsObject by defining as an optional anyObject
let nsObject: AnyObject? = NSBundle.mainBundle().infoDictionary!["CFBundleVersion"]
let version = nsObject as! String
print("app version: \(version)")


Alamofire.request(.POST, urlString , parameters: ["os" : "iphone"])

.responseData { response in

let versionXML = SWXMLHash.parse(response.data!)
let versionString = (versionXML["rss"]["channel"]["item"]["version"].element?.text)
print("version string: \(versionString)")

if let plist = Plist(name: "Info") {

let dict = plist.getMutablePlistFile()!
dict[CFBundleShortVersionKey] = versionString
//3
do {
try plist.addValuesToPlistFile(dict)
print("added")
} catch {
print(error)
}
//4
print(plist.getValuesInPlistFile())
} else {
print("Unable to get Plist")
}


}


}


plist

Answer

You can't update your (Bundle plist) at run-time. If you want use then you just make one copy on your Document Directory then you can perform any operation.

Write and Read a plist in swift with simple data

Comments