Swift: Private methods and the @objc annotation

 •  Filed under swift, ios

When you use selectors in Swift to methods that are declared private, these methods have to be annotated with @objc in order to expose the private method to the Objective C runtime.

Declarations marked private are not exposed to the Objective-C runtime if not otherwise annotated. IB outlets, IB actions, and Core Data managed properties remain exposed to Objective-C whatever their access level. If you need a private method or property to be callable from Objective-C (such as for an older API that uses a selector-based callback), add the @objc attribute to the declaration explicitly.! !