Skip to content

Assign-only Properties

Properties that are assigned but never used are identified as such:

class MyClass {
var assignOnlyProperty: String // 'assignOnlyProperty' is assigned, but never used
init(value: String) {
self.assignOnlyProperty = value
}
}

In some cases this may be the intended behavior. You have a few options available to silence such results:

  • Retain individual properties using Comment Commands.
  • Retain all assign-only properties by their type with --retain-assign-only-property-types. Given types must match their exact usage in the property declaration (sans optional question mark), e.g. String, [String], Set<String>. Periphery is unable to resolve inferred property types, therefore in some instances, you may need to add explicit type annotations to your properties.
  • Disable assign-only property analysis entirely with --retain-assign-only-properties.