It will take about 1 minutes to finish reading this article.
In Swift, there is no keyword “readonly” like Objective-C to set read-only access permissions. How can Swift implement read-only access permissions? We can do this as follows:
1 | class MyClass { |
External access is normal:
1 | let a = ClassA() |
But the following is wrong:
1 | a.title = "1234" |
The following errors will be reported:
1 | Cannot assign to property: 'title' setter is inaccessible |