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

SOLVED: Swift Error - No exact matches in call to instance method 'appendInterpolation'

Forums > SwiftUI

I'm attempting to Interpolate a String that's stored in the User Defaults. The front-end looks like this:

Text("Your organization, \(userOrganizationProperties.0) has been created")
            .font(.custom("Poppins", size: 18))
            .fontWeight(.regular)
            .frame(maxWidth: 300, alignment: .center)

I have this function accessing a data store protocol where the key/values are and returning them as Strings.

func returnOrganizationDetails() -> (String?, String?) {
  let orgName = store.organization?.name
  let orgEmail = store.organization?.organizer_email
  return (orgName, orgEmail)

}

I receive the error, "No exact matches in call to instance method appendInterpolation"

Any ideas why I'm getting this error?

4      

It's because your tuple contains Optional Strings and string interpolation can't handle Optionals. You need to use nil coalescing to provide a default value in case userOrganizationProperties.0 is nil.

So...

Text("Your organization, \(userOrganizationProperties.0 ?? "Company Inc") has been created")

or whatever.

Or, probably a better idea, provide the defaults at an earlier stage in the process, like when you pull them out of UserDefaults, and only give string interpolation actual Strings (i.e., not Optional Strings) to work with.

8      

Hacking with Swift is sponsored by Superwall

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.