Learning Center

Learning Center

Learn Menu

Class

Class is the most common entity type. It's expressed as a block statement starting with the class keyword, followed by an id and curly brackets to hold the body. Check out an empty User class example below.

  class User {

}

Properties

As of now, class body is just a set of properties. It's the same properties you use in the desktop app. Each property must have an id and a data type. Everything else is optional. Genesis syntax recognizes two types of properties:

  • Mutable: expressed with var keyword
  • Immutable: expressed with let keyword

Example

Let's add 2 properties to the empty user class from above. An ID (immutable) and a username (mutable), the result would look like this:

  class User {
    let id: int
    var username: string
}

Annotations

You might be wondering how we store the rest of the information from the desktop app. The answer is annotations. Both classes and properties support annotations.

Let's say we want to mark the id property as primary key, the code would turn into:

  class User {
    @primaryKey = true
    let id: int

    var username: string
}

We use cookies to track activity using Google Analytics & reCAPTCHA. It helps us understand what our visitors like about our product and how they interact with our website. For more information, check out our Privacy Policy.