Swift - Custom Type Class Creation

Introduction

A class is similar to a structure in many ways.

A class defines properties to store values, contains initializers to initialize its properties' values, and so on.

A class has additional capabilities not found in a structure.

Defining a Class

You define a class using the class keyword:

class ClassName {

}

Here is one example:

class Point {

}

The preceding code defines a class called Point.

When naming classes, the recommendation is to use UpperCamelCase.

To create an instance of a class, you call the class name followed by a pair of parentheses () and then assign it to a variable or constant:

var ptA = Point()

Related Topic