Setting a property's type based on the value of another property

I am starting an app for building a personal wiki. The pages in the wiki can be different types, such as text files, PDF documents, and web pages. I have the following initial model for a page:

class Page {
    var title: String = "Page"
    var type: UTType
    var contents: T
}

The data type T for contents should depend on the type of page. For example a plain text page would use a string for contents, a rich text page would use an attributed string, and a PDF page would use a PDF document.

How do I set the data type for contents so it can be different types, based on the type of page?

What you may need is an enum with associated values, like this:

enum PageContent
{
  case .plainText(String)
  case .richText(NSAttributedString)
  // etc
}

Using an enum with associated values works. Thanks.