I'm using NSClassFromString to create a class type. But I do not have the type as ClassName.Type, only as a string. Although, I'm sure this class will be with SourceProtocol. And I want to call functions of this protocol. How can I do it?
I tried casting to this protocol. But protocol doesn't have inits. Therefore I can't use functions.
And here's example
import Cocoa
protocol NeededMethods {
func doSmt(str: String) -> String
}
struct FirstImplementation: NeededMethods {
func doSmt(str: String) -> String {
str.replacingOccurrences(of: "1", with: "0")
}
}
let anyclass = NSClassFromString("FirstImplementation")
I want to call doSmt, without using FirstImplementation.Type (because it can be any class, not only FirstImplementatioon)
Post
Replies
Boosts
Views
Activity
Hello, I'm trying to launch some JS code, and it's using atob function from js. But when I launch code in swift with JSContext, I have an error ReferenceError: Can't find variable: atob.
What can I do to solve this?