Extension Must Not Contain Stored Properties

November 17, 2020

The error Extension Must Not Contain Stored Properties is common in Swift. This occurs when a variable is instantiated inside a class extension.

class MyClass: AnyObject {
}
extension MyClass: AnotherClass {
  private var foo: string = "foo"
}

Variables in Swift can only be declared within the class. To fix

class MyClass: AnyObject {
  private var foo: string = "foo"
}
extension MyClass: AnotherClass {}

For more information, check out this post by @valv0