The last line of Listing 15.23 gives the error “Partial application of ‘mutating’ method is not allowed”:
import Cocoa
struct Person {
var firstName = "Matt"
var lastName = "Mathias"
mutating func changeTo(firstName:String, lastName:String) {
self.firstName = firstName
self.lastName = lastName
}
}
var p = Person()
let changeName = Person.changeTo
pnotes
2
Same error encountered in Xcode Version 11.1
ibex10
3
Try changing struct to class:
class Person: CustomStringConvertible {
var firstName = "Matt"
var lastName = "Mathias"
func changeTo (firstName:String, lastName:String) {
self.firstName = firstName
self.lastName = lastName
}
var description : String {
return "\(firstName) \(lastName)"
}
}
var p = Person()
var changeName = Person.changeTo
print (p)
changeName (p) ("Jibber", "Jabber")
print (p)