Avoid automatic framework linking in swift
Apparently this feature is called autolinking. Swift compiler implicitly emits additional linker flags that links in all the modules the source code depends on (import Dynamic
).
There is no way to disable this entirely. But there is a private compiler flag that allows you to disable autolinking for a single framework: swiftc -disable-autolink-framework <framework>
.
Some references:
https://gist.github.com/zrzka/c89705ff634ea01aebc1
https://github.com/niw/automatic_linking_tool/blob/master/README.md
I’m pretty sure you can append -v
to swiftc
and it will print all underlying invocations as commands. Hopefully you’ll be able to see the linker invocations as well.
You should wrap the the private flag inside two -Xfrontend
flags to allow it to be used:
OTHER_SWIFT_FLAGS = "-Xfrontend -disable-autolink-framework -Xfrontend Dynamic"
For this to take effect you must still set Link Frameworks Automatically No under Apple Clang - Language - Modules.
Don't we need to link framework to XCode project anymore?
Check your project build settings. Underneath LLVM 5.1 — Language — Modules you should see the option 'Link Frameworks Automatically'. In your case it sounds like it's set to 'YES', the default.
In that case, instead of producing an error when you reference a class that the compiler doesn't know, it'll figure out which Framework contains that class and link it. In your code it'll be MKMapView
or one of the other MapKit classes that triggers the linkage.
EDIT: from the relevant 'What's New?' document:
Auto Linking is enabled for frameworks imported by code modules. When
a source file includes a header from a framework that supports
modules, the compiler generates extra information in the object file
to automatically link in that framework. The result is that, in most
cases, you will not need to specify a separate list of the frameworks
to link with your target when you use a framework API that supports
modules.
Another way of looking at it is that the compiler is smart enough to mutate #import
to @import
when the framework has been built appropriately. All system frameworks have been.
Problems linking iOS app with custom framework
First, create the iOS framework project, being sure to set the Installation Directory
(INSTALL_PATH
) build setting for the framework target to @rpath
. I would change the Xcode scheme to make it a shared scheme. Now close the framework project, to be sure it can be opened when we import it into the App project in the following steps.
Next, create the iOS App project. Similar to how you did, I created an App (Debug)
scheme and a App (Release)
scheme. I created a Frameworks
group in the App project similar to the image shown below. Then I located the .xcodeproj
file of my framework I just created, and dragged it into that Frameworks
group. Open the disclosure triangles to reveal the framework project's Products
like shown in the image below. Drag it to the Embedded Binaries
section in the General
section of the app target. Doing so should automatically add the other steps you would need to take to get things to work properly (I believe these include adding the framewokr as a dependency, linking against the framework, and copying the framework into the built app).
The last step is to make sure the framework can be found at compile time. In the app target's build settings, be sure to set Framework Search Paths
(FRAMEWORK_SEARCH_PATHS
) to $(BUILT_PRODUCTS_DIR)
. When you select the scheme for the app that builds in a Develop build style, the framework will be built in the same build style in the same directory as the app itself.
Related Topics
Integer Literal Overflows When Stored into 'Int'
Sf Symbols Hierarchical, Palette, and Multicolor Rendering Mode Colors
Generic Within a Generic in Swift
Check If a Character Is Lowercase or Uppercase
Dictionary of String:Any Does Not Conform to Protocol 'Decodable'
Swift Build Time Too Long When the Configuration Is 'Release'
How to Use a Protocol with Optional Class Methods in an Extension with Generic in Swift
How to Use Multiple Mtlrenderpipelinestates in One Mtlrendercommandencoder
How to Get Notification Authorization Status in Swift 3
Counting Coloured Pixels on the Gpu - Theory
How to Get Part of a String in Swift
Zposition of Sknode Relative to Its Parent
Swift- How to Display Image Over Button
Google Sign-In via Firebase: Gidsignindelegate Does Not Conform to Viewcontroller
Type Check Operator (Is) for Check VS Homogenous Protocol: Why Can This Be Done for Optionals
Xcode11 Error "Open(_:Options:Completionhandler:) Is Unavailable in Application Extensions"