'NSString' does not conform to expected type 'CVarArg'

Hi everyone, I'm getting this error while deploying my API in HEROKU :/

error: argument type 'NSString' does not conform to expected type 'CVarArg'
remote: let validatePhone = NSPredicate(format: "SELF MATCHES %@", phoneNumberRegex as NSString)
remote: ^
remote: as! CVarArg
remote: ! Push rejected, failed to compile Swift app.
remote: ! Push failed
remote: Verifying deploy...
this is my code :

func validatePassword(password: String) -> Bool {
//Minimum 8 characters at least 1 Alphabet and 1 Number:
let passRegEx = "^(?=.\d)(?=.[a-z])(?=.[A-Z])(?=.[a-zA-Z]).{8,}$"
let trimmedString = password.trimmingCharacters(in: .whitespaces)
let validatePassword = NSPredicate(format:"SELF MATCHES %@", passRegEx as NSString)
let isvalidatePassword = validatePassword.evaluate(with: trimmedString)
return isvalidatePassword


Have you seen this Stack Overflow answer? It looks like you can't print strings using the %@ specifier with Vapor because not all parts of the Foundation framework are available in Vapor yet.

The solution seems to be to use the %s format specifier with a C-string.

Hope this helps!

1 Like
Terms of Service

Privacy Policy

Cookie Policy