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 Transform your career with the iOS Lead Essentials. Unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer and a FREE crash course.

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.