I need to print String
inside the String
extensions. I am aware the addition of one String
with another String
. But,
Why below code give me an error?
Is it possible to solve this error with this way?
If yes, How?
Code:
extension String{
func fruit(){
//After some manipulation with self I need to print
print("Apple".parent("Tree"))
print("Tomato".parent("Plant"))
}
mutating func parent(_ word:String){
self = self+" "+word
}
}
Error :
Cannot use mutating member on immutable value of type 'String'