Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect in runtime that app uses swift

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.

like image 475
Alexander Zakatnov Avatar asked Sep 06 '25 04:09

Alexander Zakatnov


1 Answers

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
}
like image 85
Asperi Avatar answered Sep 09 '25 05:09

Asperi