Post

Replies

Boosts

Views

Activity

Using protocol functions at unknown class
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)
5
0
699
Dec ’21
Base64 encoding in JSContext
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?
Replies
1
Boosts
0
Views
1.4k
Activity
Dec ’21
Using protocol functions at unknown class
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)
Replies
5
Boosts
0
Views
699
Activity
Dec ’21