Using -enable-implicit-dynamic in Xcode

Hello. I'm trying to use -enable-implicit-dynamic in Xcode, as a way of swizzling methods in a library (SwiftUI specifically). I want to be able to automatically instrument some SwiftUI code. Unfortunately, adding that flag in the "other Swift flags" field gives an error saying that it's not recognized. The version of Swift is the one from Xcode 12.5 (Apple Swift version 5.4, swiftlang-1205.0.26.9 clang-1205.0.19.55). Am I using this flag wrong, or is what I want to do just not possible?

It's a frontend flag so you have to pass it with -Xfrontend:

% swiftc -enable-implicit-dynamic
error: unknown argument: '-enable-implicit-dynamic'
% swiftc -Xfrontend -enable-implicit-dynamic
error: no input files

Thanks! That got rid of that error. Unfortunately, it then tells me that the method is not marked as dynamic. I'm guessing this won't let me swizzle inside of libraries like SwiftUI?

not sure this fits your use case, but have you tried GitHub - johnno1962/InjectionIII: Re-write of Injection for Xcode in (mostly) Swift ?

Unfortunately, that doesn't appear to work standalone on the device.

i see, its too bad

just a guess, but maybe on-device hot-patching must have some hard limitation (maybe code signing or special entitlement) that makes it not possible...

@stevemalsam
Did u manage to turn on the flag?
It would be interesting to try and swizzle swiftUI, I think.

I managed to enable it. Instead of passing it as one argument like "-Xfrontend -enable-implicit-dynamic", I had two create to entries:

1 Like