swift object

Hi all,


Sorry I am beginner in swift, I have a very simple question about object, I would like to add manage subobject in my main object but I don't know how to do it, could you please help ?


My main object:

class
Person {
   var ID : int
    
var
firstName: String?
   
var
lastName: String?
    var TaskList : Task() //(should be optional)
}


My sub object

Class Task {

var Name : String

var Description : String

var DueDate : Date

}

Many thanks

Sebastien

var TaskList : Task()

This line looks like it shouldn't compile - you can say the variable is of type Task using the : or you can initialise it by calling the Task() initialiser and assigning to the variable using = (and have the compiler infer that 'Task' is the type. i.e. one of these options

var taskList : Task
var taskList = Task()


To make taskList optional, you'd do this:

class Person {
   var taskList : Task? = Task()
}
swift object
 
 
Q