Blazej SLEBODA
Blazej SLEBODA

Reputation: 9925

Public class with a private functions by default

I have a public class with a multiple private properties and private functions. For each private element of the class I have to add private access modifier.

Is it possible to set up a multiple properties and functions to private in a public class with a minimal use of "private" keyword?

class Car {

  var property: String
  private var property1: String
  private var property2: String
  private var property3: String

  func action()
  private func actionA()
  private func actionB()
  private func actionC()

}

Upvotes: 0

Views: 641

Answers (1)

Binary Pulsar
Binary Pulsar

Reputation: 1209

If you really wanted to you could use the following for properties:

private var property1: String, property2: String

You can't do the same for methods. Maybe one day this will be supported:

private extension Car {
  func action() {}
}

Upvotes: 2

Related Questions