-
-
Save alemar11/d2ed3a90dd437267b156f8f33996e8af to your computer and use it in GitHub Desktop.
This file contains 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
// a.swift | |
public dynamic func f() { | |
print("original") | |
} | |
// b.swift | |
import a | |
@_dynamicReplacement(for: f()) | |
public func f_b() { | |
print("replacement in b") | |
} | |
// c.swift | |
import Foundation | |
import a | |
f() | |
let file = URL(fileURLWithPath: "/path/to/libb.dylib") | |
guard let handle = dlopen(file.path, RTLD_NOW) else { | |
fatalError("dlopen failed") | |
} | |
f() | |
/* | |
$ swiftc -emit-module -module-name a a.swift | |
$ swiftc -emit-library -module-name a a.swift | |
$ swiftc -emit-library -module-name b -I. liba.dylib b.swift | |
$ swiftc -emit-executable -module-name c -I . liba.dylib c.swift | |
$ ./c | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment