GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

error: 'Expected named member of numeric literal' on the String(1.1.1)

Forums > SwiftUI

Hi everyone, I am getting this error: 'Expected named member of numeric literal' on the String(1.1.1). I tried already to convert it in different formats, but it didn't worked - any suggestions?

if savedVersion != String(1.1.1) || savedVersion != String(1.1) || savedVersion != String(1) {

}

2      

1.1 is a numeric literal (a Double, or possibly a CGFloat or some other type, depending on how it was declared)

1.1.1 is not a number at all in Swift, but rather an attempt to access a property .1 on a value 1.1, which does not exist and therefore gives you that error. The "named literal" part is because the compiler is expecting a named element rather than an indexed element like you would find on, say, a tuple.

It looks like you might be trying to compare app version information. If so, check out this blog post for some ideas how to do that properly:

How to compare two app version strings in Swift

2      

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.