Building a XCFramework without objective-c interop

I'm trying to build a XCFramework for an application with iOS 10.3 deployment target requirement.

This framework is distributed internally in the company, until now it was being built as a universal framework (with lipo). As we are evolving the applications to use XCode 13.2.1 to met App store submission requirement ( App Store submission requirement starts April 25 - News - Apple Developer ), we are trying to evolve the framework as well to be built as a xcframework.

The issue we are facing when embedding the xcframework is related to a common pattern used in the code that is having a class extending a framework class, and then creating protocol extensions to implement UIKit methods, like this:

'@objc' instance method in extension of subclass of 'RandomColorsView' requires iOS 13.0.0
Non-'@objc' method 'tableView(_:numberOfRowsInSection:)' does not satisfy requirement of '@objc' protocol 'UITableViewDataSource'

This seems to be related with the .swiftinterface generated with the classes and class members being marked with the @objc attribute (on the right).

Since we can't change the deployment target yet, I have some questions:

  1. Is there a option to build a xcframework without the objc interop support?
  2. Is there any plans on dropping support to universal frameworks in the future that would require frameworks being distributed as xcframeworks?
  3. Can I continue building it as a universal framework since it is distributed internally and I don't need features like library evolution? (although the xcframework's multiplatform feature would be handy)

You don’t need library evolution to build an xcframework. Universal frameworks were never going to work once ARM Macs became a thing (the simulator slice is also arm64), but that doesn’t mean you have to turn on “Build Library for Distribution” since you are not, in fact, planning to distribute the library [independently of its clients].

2 Likes

I've tried setting "Build Library for Distribution" to No, but it doesn't seem to build anything, is there any additional step?

It generates a folder with only a Info.plist

You have to pass -allow-internal-distribution to xcodebuild -create-xcframework, as by default it only accepts libraries built in evolution mode.

3 Likes

Ack, sorry, I forgot about that, yeah. It’s in the help for -create-xcframework.

2 Likes

Thanks @jrose and @tgoyne, setting "Build Libraries for Distribution" to No and passing -allow-internal-distribution on xcodebuild worked!
It builds successfully, and the .swiftinterface was generated without the @objc attributes, solving the error.

Is there any documentation where I can read more about it?

Everything related to xcframeworks is pretty minimally documented, and if there's anything official about this in particular other than the one sentence in xcodebuild -create-xcframework -help I haven't been able to find it.

3 Likes

Thanks for the help! I'm the dev mentioned in the doc comments!

1 Like