Complete the code to define a method named greet inside the struct.
struct Person {
var name: String
func [1]() {
print("Hello, \(name)!")
}
}The method name should be greet as defined in the instruction.
Complete the code to call the greet method on the person instance.
var person = Person(name: "Anna") person.[1]()
To call the method defined as greet, use person.greet().
Fix the error by completing the method signature to modify the struct's property.
struct Counter {
var count = 0
mutating func [1]() {
count += 1
}
}The method name increment clearly indicates increasing the count by one.
Fill both blanks to create a method that returns a greeting with the person's name.
struct Person {
var name: String
func [1]() -> String {
return "Hello, \([2])!"
}
}The method is named greet and it returns a string using the property name.
Fill all three blanks to define a mutating method that resets the count to zero and returns a message.
struct Counter {
var count: Int
mutating func [1]() -> String {
count = [2]
return "Count reset to [3]"
}
}The method named reset sets count to 0 and returns a message with the word 'zero'.
