Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to instantiate a SwiftUI view from a string?

Tags:

swift

swiftui

Is it possible to convert a string to a SwiftUI view? Something like JavaScript's eval(). In the code below I'm looking for an XXX function.

let uiString: String = “VStack { Text(\“hi there\”) }”
let view: some View = XXX(uiString)
like image 861
Norman Avatar asked Nov 15 '25 10:11

Norman


1 Answers

  1. No, because Swift is compiled to machine code. There isn't an interpreter to evaluate arbitrary expressions on the go.
  2. That sounds a lot like a security vulnerability. Why would you want to do that?
like image 164
Ayxan Haqverdili Avatar answered Nov 18 '25 21:11

Ayxan Haqverdili