marciokoko
marciokoko

Reputation: 4986

Converting string to float in Apple Swift yields value not identical to module error

I can print out my string systemVersion with println and I get:

8.0

But when I try to convert it using:

float(systemVersion)

I get two errors saying:

Expected module member name after module name

&

(@lvalue string) -> ST1 is not identical to module

What could that possibly mean?

Upvotes: 1

Views: 1839

Answers (2)

Jean Le Moignan
Jean Le Moignan

Reputation: 22236

Being from a country where the decimal indicator is a "," and not a ".", I immediately smelled something.

Here, if you do this in a playground:

let systemVersion = "8.0"
Float(systemVersion)

you'll get a healthy float with the right value (notice the comma).

However, if you do the same with a dot:

let systemVersion = "8,0"
Float(systemVersion)

you'll get an error (could not find an overload for 'init' that accepts the supplied arguments).

Could your problem be related to the decimal format in your country? Bye,

Upvotes: 0

Cezar
Cezar

Reputation: 56362

You should use systemVersion.bridgeToObjectiveC().floatValue, or (systemVersion as NSString).floatValue

Upvotes: 1

Related Questions