Is it possible to convert a file containing only swift classes into a real class. And the class in the text file.
And the classes in the text follow a protocol, and this protocol exists in the running swift
For example, I have A.swift and B.swift, A.swift has a protocol AP, B.swift has a class BC, and BC follows the AP protocol. Now I run A.swift, in which I want to use the B.swift class in the program.
If this can be achieved, swift can be used for data transmission like json.
Ultimately all data transmission is happening in bytes.
You need to think about:
What operations do want to do on your data when it is loaded in program memory.
How to model in-memory representation of your data.
How to structure serialized representation.
How to convert between in-memory and serialized representations.
Looks like you want your serialized representation to be Swift source code. Swift source code can contain a lot things, including imports of frameworks, declarations of custom operators, conditional compilation directives, and arbitrary executable code which pose security risks. Is this really the best representation of your data?
Note that JSON is inspired by JavaScript, but normally JSON is not parsed by feeding it into full-powered JS interpreter. For several reasons, but for security reasons in particular. If you have some specific requirements that JSON does not satisfy (maybe native representation of dates), you could design your own data format and take some inspiration from Swift. But it would a new thing, completely different from the Swift programming language.