With lldb, I want to instantiate a Swift Class in my release iOS build and release dynamic framework.
I attach lldb to my release build, on the Simulator.
Main app - works
(lldb) exp let $c = hello_class()
error: <EXPR>:3:10: error: use of unresolved identifier 'hello_class'
let $c = hello_class()
^~~~~~~~~~~
(lldb) expr import My_App
(lldb) exp let $c = hello_class()
(lldb) po $c.hello()
🔸 hello 🔸
dynamic framework - fails
(lldb) dclass -m myframework
Dumping classes
************************************************************
myframework.RustyAppInfo
(lldb) expr import myframework
(lldb) expr let $d = RustyAppInfo()
error: Couldn't lookup symbols:
__T011myframework12RustyAppInfoCACycfC
Both the app and dynamic framework were built with no optimization.
UPDATE
static framework - fails
Same results when changing - to the Xcode 9 introduced feature - static Swift framework.
Xcode - Dead Code Stripping
by default, with Swift code, Dead Code Stripping
is turned ON. I checked to see if that was the issue. No difference to results.
RESOLVED
I found my answer inside of this article:
http://iosbrain.com/blog/2018/01/13/building-swift-4-frameworks-and-including-them-in-your-apps-xcode-9/
I had failed to set public init()
on the Swift class that was inside the Framework. Working code that can be invoked by lldb:
// set the Framework class to Public
public class rnHello{
// set the initializer to public, otherwise you cannot invoke class
public init() {
}
// set the function to public, as it defaults to internal
public static func world() {
print("hello from a static method")
}
}
Now you can access this via your Swift code or with lldb:
(lldb) po rnHello.world()
hello from a static method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With