Creating a class or structure

We use the same syntax to define classes and structures. The only difference is we define a class using the class keyword, and a structure by using the struct keyword. Let's look at the syntax used to create both classes and structures:

class MyClass {
  // MyClass definition
}

struct MyStruct {
  // MyStruct definition
}

In the preceding code, we define a new class named MyClass and a new structure named MyStruct. This effectively creates two new Swift types named MyClass and MyStruct. When we name a new type, we want to use the standard naming convention set by Swift where the name is in camel case, with the first letter being uppercase. Any method or property defined within the class or structure should also be named ...

Get Mastering Swift 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.