mardi 19 juillet 2016

Version checker fails when comparing numbered strings "16" != "16.0" using the NSComparisonResult class [duplicate]

This question already has an answer here:

Consider this block of code which uses NSComparisonResult, what can I do to make this return false? This should be able to parse strings that have multiple decimal points.

let currentInstalledVersion = "16"
let currentAppStoreVersion = "16.0"

var newVersionExists = false

if (currentInstalledVersion.compare(currentAppStoreVersion, options: .NumericSearch) == NSComparisonResult.OrderedAscending) {
    newVersionExists = true 
}

newVersionExists Outputs to true in playgrounds.

Currently

Could someone explain why that is the case?

Aucun commentaire:

Enregistrer un commentaire