4

I'm developing framework(objc) and I need to detect that application uses swift. It doesn't matter that app developed on swift completely or it's swift/objc hybrid.

Do you have and ideas how to get this information? I've thought about objc runtime but I don't know how I can implement that.

Great thanks.

I don't know why my previous question has been closed. But I'll try to be more focused: I need to get information how many clients which integrate my framework use swift as a programming language so I must to detect that a project uses swift.

4
  • 2
    First, no, it's highly unlikely you could detect that Swift was used. iOS apps are compiled... not interpreted. Second, even if you could, how would you be getting that information? Are you planning on putting some type of functionality in your framework that (secretly) sends data to your server when a user runs an app? Commented Jan 23, 2020 at 21:44
  • 1
    @DonMag maybe his stuff in fact is a reporting framework or has one as a dependency. Sending the described data shouldn't be that hard together with that all the other data-points that make marketing people happy. Commented Jan 23, 2020 at 22:36
  • @DonMag I just want to collect a statistics Commented Jan 24, 2020 at 9:30
  • @Till exactly :) Commented Jan 24, 2020 at 9:35

1 Answer 1

4

Please find below the possible approach based on public documented dyld API available since iPhone2 and valid for all modern iOS versions. And libswiftCore.dylib is present always for swift.

Taking into account that Swift might be in some application plug-ins, the below function should be called regularly (or at least till first positive result) on your framework API call.

#import <mach-o/dyld.h>

BOOL isSwiftLoaded() {
    return NSVersionOfRunTimeLibrary("libswiftCore.dylib") != -1; 
            // -1 is documented indicator that library is not loaded
}
Sign up to request clarification or add additional context in comments.

2 Comments

That's great solution! Many thanks! Can you say where did you find the solution? I've read apple's documentation and a lot of other articles but I've never seen before your really great solution.
Just experience... and all good habit, from C background, to read API headers/interfaces, even before documentation. ))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.