Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[swift2objc] Add support for private setters on variables #2049

Open
nikeokoronkwo opened this issue Mar 2, 2025 · 0 comments
Open

[swift2objc] Add support for private setters on variables #2049

nikeokoronkwo opened this issue Mar 2, 2025 · 0 comments

Comments

@nikeokoronkwo
Copy link
Contributor

From https://docs.swift.org/swift-book/documentation/the-swift-programming-language/accesscontrol#Getters-and-Setters:

You can give a setter a lower access level than its corresponding getter, to restrict the read-write scope of that variable, property, or subscript. You assign a lower access level by writing fileprivate(set), private(set), internal(set), or package(set) before the var or subscript introducer.

When exporting to Objective-C, the properties are marked as readonly. See the example below

class MyClass {
  public var myPublicProperty: String
  public private(set) var myPrivateSetterProperty: String
}
// implementation in Objective-C
@interface MyClass : NSObject
@property (nonatomic) NSString myPublicProperty;
@property (nonatomic, readonly) NSString myPublicProperty;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant