Ali
Ali

Reputation: 515

Class type properties should not have static keyword?

  1. This is an image from Apple's documentation example, Why do the first 2 properties have the 'static' keyword?? I thought static should be only used for structures and enums?

  2. Secondly, why does this class have a stored type property? I thought classes could only have computed type properties???

enter image description here

Upvotes: 2

Views: 388

Answers (2)

ABakerSmith
ABakerSmith

Reputation: 22939

From the Xcode 6.3 (Swift 1.2) release notes, under Swift Language Enhancements:

static methods and properties are now allowed in classes (as an alias for class final).

You are now allowed to declare static stored properties in classes, which have global storage and are lazily initialized on first access (like global variables).

Upvotes: 2

Rob
Rob

Reputation: 437392

  1. Effective Swift 1.2, static properties are now permitted in classes.

  2. Classes have always been permitted to have stored properties.

Upvotes: 2

Related Questions