-1

I'm making a swift package using existing code to separate a class as a module from the main project.

My original code makes properties private(set), which is intended to make it only readable (not settable).

// Original code
// A property of the class
@Published private(set) var index: Int = 0

But Xcode reports an error 'index' is inaccessible due to 'internal' protection level. I assume I have to change the private(set) into public. But I also want to protect it from editing outside of the class, which means still using private(set). Is there any syntax to do it?

Yiming Designer
  • 423
  • 3
  • 10

1 Answers1

2

Every property has a combination of accessibilities for get and set.

The default is

internal internal(set)

You seem to want

public private(set)