XCFramework requires to target iOS 13 for inter-framework dependencies with Objective-C compatibility (tested with Xcode 11 beta 7)

There are two issues when using XCFramework for inter-framework dependencies with Objective-C compatibility which did not cause any problems when creating normal frameworks. It seems that the XCFramework issues can only be resolved when targeting iOS 13.0.

It would be quite convenient to have these issues resolved in order to distribute libraries compiled and bundled as XCFrameworks without sacrificing backwards compatibility for any iOS version older than iOS 13.

In order to demonstrate the two issues just build the DerivedFramework target with Xcode 11.0. The sample project can be found here: https://github.com/schiewe/XCFrameworkIssue

Issue 1) https://github.com/schiewe/XCFrameworkIssue/blob/f84ec25145f63f93badbe845a282bb21e18967eb/DerivedFramework/DerivedClass.swift#L8 causes a Method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C error.

Issue 2) https://github.com/schiewe/XCFrameworkIssue/blob/f84ec25145f63f93badbe845a282bb21e18967eb/DerivedFramework/DerivedClass.swift#L15 causes a '@objc' instance method in extension of subclass of 'BaseClass' requires iOS 13.0.0 error.

It seems like these issues are compiler bugs which will hopefully be fixed but it might also be a "feature".
What do you think?

1 Like

Xcode 11 GM Seed yields the same issues.

Also see issue 2 in the GM released yesterday. I fixed some of the errors by moving the extension functions to the class declaration scope. Not a great workaround and can't really be done in some situations. :man_shrugging:

It also does not seem to matter if BUILD_LIBRARY_FOR_DISTRIBUTION is enabled or not. I still get issue 2

Someone correct me if I am wrong but I believe this is due to changes in Swift ABI as a result of SE-0260.
I suspect that iOS 13 probably ships with a version of Swift Libraries that support Library Evolution.

Quoting SE-0260:

Binaries compiled without this mode should not be declared as ABI-stable. While they should be stable even without library evolution mode turned on, doing this will not be a supported configuration.

Is this confirmed a bug or a limitation?

Official answer from Apple in German:

Dies ist so erwartet. Die Verwendung von @objc-Methoden in Erweiterungen von @objc-Klassen beim Erstellen eines Framework für die Verteilung erforderte Änderungen an der Objective-C-Laufzeit, die nur in iOS 13 (und neuer) verfügbar sind. Du kannst entweder diese Methoden in die Klassendefinition selbst verschieben oder du verschiebst das @objc-Attribut.

In summary, yes, it is a confirmed limitation.

1 Like
Terms of Service

Privacy Policy

Cookie Policy