0

I have some code in Swift and I'd like to insert a property of the app (the version). Is this possible?

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, ] 

Note: This is not a duplicate of iOS app, programmatically get build version because my question is about how to do it the right way using Swift (as opposed to Objective-C)

0

1 Answer 1

0

This is an answer I pieced together from another question on here but I am also wondering if anyone has comments or knows a better/cleaner way of doing it.

 //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, ] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.