1

I want to write a PAT and I don't care about Obj-C interoperability. The @nonobjc attribute sounds perfect but its designed for variables and methods only. Anything similar for hiding protocols from Obj-C?

Bowdus
  • 33
  • 3

1 Answers1

2

You seem to be misunderstood what the @nonobjc attribute is for:

From the docs:

nonobjc

Apply this attribute to a method, property, subscript, or initializer declaration to suppress an implicit objc attribute.

If you scroll further down the page, it tells you what will have an implicit objc attribute on them:

The compiler implicitly adds the objc attribute to subclasses of any class defined in Objective-C. However, the subclass must not be generic, and must not inherit from any generic classes. [...] The objc attribute is also implicitly added in the following cases:

  • The declaration is an override in a subclass, and the superclass’s declaration has the objc attribute.
  • The declaration satisfies a requirement from a protocol that has the objc attribute.
  • The declaration has the IBAction, IBSegueAction, IBOutlet, IBDesignable, IBInspectable, NSManaged, or GKInspectable attribute.

This does not include protocols, so protocols are never implicitly exposed to Objective-C. This means that you don't need the nonobjc attribute on protocols to suppress implicit objcs on protocols. Protocols, by default, are not exposed to Objective-C, unless you mark them with @objc.

Sweeper
  • 213,210
  • 22
  • 193
  • 313
  • This is the direction I was heading. I was trying to provide a default implementation that handled UITableViewDataSource. https://stackoverflow.com/a/39604189/13074633 – Bowdus Mar 17 '20 at 07:06