Complete the code to declare a struct named Person.
struct [1] {
var name: String
}The keyword struct is followed by the struct name, which should start with a capital letter by convention. Here, Person is the correct struct name.
Complete the code to add an integer property called age to the struct.
struct Person {
var name: String
var [1]: Int
}The property name should be age in lowercase to follow Swift naming conventions.
Fix the error in the struct declaration by completing the missing keyword.
[1] Person {
var name: String
var age: Int
}The keyword struct is required to declare a struct in Swift.
Fill both blanks to declare a struct with a method that returns a greeting.
struct Person {
var name: String
func [1]() -> String {
return "Hello, \(self.[2])!"
}
}The method name is greet and it uses the property name to return a greeting.
Fill all three blanks to declare a struct with a computed property that returns a description.
struct Person {
var name: String
var age: Int
var [1]: String {
return "\(self.[2]) is \(self.[3]) years old."
}
}The computed property is named description and it returns a string using the name and age properties.