我可以快速将字符串转换为代码块吗? [英] Can I turn a string into a block of code in swift?

查看:49
本文介绍了我可以快速将字符串转换为代码块吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将字符串转换为代码块?我正在向我的网站发出Ajax请求,该网站的端点返回一些快速代码作为字符串.我可以将代码以字符串的形式返回,但是我无法运行该代码,因为它不知道它是代码.

Is there any way to turn a string into a block of code? I'm making an Ajax request to a website of mine that has an endpoint that returns some swift code as a string. I can get that code back as a string, but I can't run that code because it doesn't know that it is code.

推荐答案

不,您不能这样做.Swift是一种编译语言,不像Ajax那样解释.

No, you can't do that. Swift is a compiled language, not interpreted like Ajax.

Swift编译器在Mac上运行,而不在iOS设备上运行.(对于Objective-C同样如此).

The Swift compiler runs on your Mac, not on the iOS device. (The same is true for Objective-C).

此外,Apple的应用程序商店指南禁止向您的应用程序提供可执行代码,因此,即使您想出了一种方法,也可能会拒绝您的应用程序.

Plus, Apple's app store guidelines forbid delivering executable code to your apps, so even if you figured out a way to do it, your app would be rejected.

请注意,随着Swift游乐场的出现,可以在iPad上运行Swift编译器.近期的高端iPhone也许也能胜任这项工作,但是您必须弄清楚如何安装它.

Note that with the advent of Swift playgrounds, it is possible to run the Swift compiler on an iPad. Recent high-end iPhones are probably also up to the job, but you'd have to figure out how to get it installed.

但是,如上所述,Apple的应用商店指南禁止您在运行时向应用交付代码.

As stated above though, Apple's app store guidelines forbid you from delivering code to your apps at runtime.

这篇关于我可以快速将字符串转换为代码块吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆