使用Swift在字符串中插入应用程序版本?
我在Swift中有一些代码,我想插入应用程序的属性(版本)。这可能吗使用Swift在字符串中插入应用程序版本?,swift,plist,Swift,Plist,我在Swift中有一些代码,我想插入应用程序的属性(版本)。这可能吗 var parameters: [String : AnyObject] = [ "offerSef" : url, "userGuid" : user.userGuid, "bottlesQty" : quantityIndex + 1, "appId" : "iOS" + /* WANT TO INSERT APP VERSION HERE */, "creditCardId" :
var parameters: [String : AnyObject] = [
"offerSef" : url,
"userGuid" : user.userGuid,
"bottlesQty" : quantityIndex + 1,
"appId" : "iOS" + /* WANT TO INSERT APP VERSION HERE */,
"creditCardId" : payment.paymentID,
"billingAddressId" : payment.billingAddressId,
]
注意:这不是重复的,因为我的问题是关于如何使用Swift(与Objective-C相反)以正确的方式进行操作。这是我从这里的另一个问题拼凑而成的答案,但我也想知道是否有人对此有意见或知道更好/更干净的方法
//First get the nsObject by defining as an optional anyObject
if let nsObject: AnyObject? = NSBundle.mainBundle().infoDictionary["CFBundleShortVersionString"] {
//Then just cast the object as a String, but be careful, you may want to double check for nil
if let version = nsObject as String {
appId = appId + "-" + version
}
}
var parameters: [String : AnyObject] = [
"offerSef" : url,
"userGuid" : user.userGuid,
"bottlesQty" : quantityIndex + 1,
"appId" : appId,
"isMobile" : true,
"creditCardId" : payment.paymentID,
"billingAddressId" : payment.billingAddressId,
]