UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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 RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.