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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.