Add -ObjC linker flag to UIKitNavigation target#337
Open
connor-krazy7 wants to merge 2 commits intopointfreeco:mainfrom
Open
Add -ObjC linker flag to UIKitNavigation target#337connor-krazy7 wants to merge 2 commits intopointfreeco:mainfrom
connor-krazy7 wants to merge 2 commits intopointfreeco:mainfrom
Conversation
UIKitNavigationShim is an ObjC target that swizzles UIViewController (viewDidAppear/viewDidDisappear) via +load and adds categories like set_UIKitNavigation_onDismiss:. When UIKitNavigation is built as a dynamic framework, the linker dead-strips these ObjC symbols because no Swift code references them directly. Adding -ObjC forces the linker to include all ObjC categories, fixing "unrecognized selector" crashes at runtime.
Member
|
Hi @connor-krazy7, packages are allowed to use unsafe flags only in Swift 6.2 and up (see this discussion), and so at the very least this would necessitate moving this Package.swift to Package@swift-6.0.swift and creating a new Package.swift for 6.2. |
Package.swift (6.2+) includes -ObjC on UIKitNavigation to prevent dead-stripping of UIKitNavigationShim's ObjC categories when built as a dynamic framework. Package@swift-6.0.swift preserves the original manifest for pre-6.2 consumers where unsafeFlags are not allowed in versioned dependencies.
Author
Thanks for the comment, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
UIKitNavigationis built as a dynamic framework (e.g. in a modularized project with multiple dynamic targets), the linker dead-strips ObjC symbols fromUIKitNavigationShimbecause no Swift code references them directly. This causes an "unrecognized selector" crash at runtime:The
UIKitNavigationShimtarget contains ObjC code that:viewDidAppear:/viewDidDisappear:via+loadUIViewController(set_UIKitNavigation_onDismiss:,set_UIKitNavigation_hasViewAppeared:, etc.)Adding
-ObjCtoUIKitNavigation's linker settings forces the linker to include all ObjC categories from the statically linkedUIKitNavigationShimtarget, fixing the crash.Reproduction
UIKitNavigation(e.g. viaComposableArchitecture)present(item:content:)to present a view controllerset_UIKitNavigation_onDismiss:unrecognized selector