Complete the code to define a method named greet inside the struct.
struct Person {
func [1]() {
print("Hello!")
}
}The method name should be greet as required.
Complete the code to call the greet method on the person instance.
let person = Person()
person.[1]()To call the method defined earlier, use greet().
Fix the error by completing the method signature to accept a name parameter of type String.
struct Person {
func greet([1] name: String) {
print("Hello, \(name)!")
}
}The correct external parameter name is for to read naturally as greet(for name: String).
Fill both blanks to define a method that returns a greeting string and call it.
struct Person {
func greet() -> [1] {
return "Hello!"
}
}
let person = Person()
let message = person.[2]()The method returns a String and is called greet().
Fill all three blanks to define a method with a parameter and call it with an argument.
struct Person {
func greet([1] name: [2]) -> String {
return "Hello, \(name)!"
}
}
let person = Person()
let message = person.greet([3]: "Alice")The method uses external parameter name for, parameter type String, and is called with the string "Alice".
