Ubuntu Os
Ubuntu Os

Reputation: 1

Why is this string comparison not working?

I have defined a function in swift that will take two strings as parameters and return true if they are the same:

func compareString(f_string:String,S_string:String)->Bool{
   if f_string == S_string{
      return true
   }
}

Why does it show an error message?

Upvotes: 0

Views: 285

Answers (1)

Sourabh86
Sourabh86

Reputation: 744

your function is supposed to return a boolean value everytime, but it returns only when the strings are equal. add a return false statement after if and it should work.

func compareString(f_string:String,S_string:String)->Bool{
   if f_string == S_string{
      return true
   }
return false
}

Upvotes: 2

Related Questions