Convert class properties to static var's (instead of class funct's)

Description

Customer's report:

Converter converts readonly class properties to class func's instead of static var's. If the property is defined readonly in header and implementation provides a computed value, the computation should not be converted to class function but a static variable with a closure with the code. It retains the meaning of the code better.

  1. This sample should produce the following (see the statickeyword):

NOTE: we’re using staticinstead of classas in the Xcode’s Generated Interface (and the above article),

because only staticvariables can be initialized.

See this article for differences between static and class in Swift.

 

2. This sample (which includes getters and setters)

should merge (static) accessor method implementations into the (static) property declaration,

very similar to how regular (non-static) properties and methods are handled.

The output should be:

NOTE: here we are using classinstead of staticfor the printSelected property declaration to allow inheritance.

A quick test shows that in Objective-C, you can declare a class property with the same name in a subclass: https://take.ms/6BYVz

In Swift, this is only possible with a class keyword, but not with “static”.

 

Conclusion: use class for static property with accessor(s) or static` or static property without accessors.

Environment

None

Activity

Show:
Alex Petuschak
October 17, 2018, 4:24 PM

Assignee

Alex Petuschak

Reporter

Alex Petuschak

Labels

Git Branch Name

None

GitHub Issue

None

Components

Fix versions

Priority

Medium
Configure