I'm creating framework in Swift and going to support both Swift and Objective-C. I repeatedly used @objcMembers on class to expose public properties and methods. Today, I noticed that non-public aka internal properties were accessible from Objective-C. Is there a way to hide internal properties and methods while using @objcMembers ?
@objc attribute expose internal property
tbh internal should be treated as private to objective-c level or in case swift / objc mixing framework, there should be a compiler option how to interpret internal keyword.. internal(set) is now exposed to objc so I need to make every single one of them to be private and make additional setter methods to access within framework.
Personally I view @objcMembers as a convenience for folks moving from early versions of Swift that made properties available to Objective-C by default. In modern code I just add @objc to each property that I want exposed that way. It’s not a huge burden IMO.
This is born out by The Swift Programming Language which says “Most code should use the objc attribute instead”.
there should be a compiler option how to interpret internal keyword
Changes like that have to go through Swift Evolution, and you should feel free to make your case there.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"