![]() I strongly advice you to read the official documentation regarding the JavaScriptCore framework. For a full list regarding these methods, take a look here. For example, a JSValue can be converted to a String using the toString() method, or to a dictionary using the toDictionary() method (more about that later in action). However, there are methods that make the conversion to specific datatypes easy. That means that if you access a JavaScript variable and a JavaScript function from Swift, both are considered to be JSValue objects. We’ll use it extensively, but the use cases are going to be similar in most of the times.Īll values in JSContext, are JSValue objects, as the JSValue class represents the datatype of any JavaScript value. As you’ll discover in the next parts, the JSContext class is our mean for exposing Swift code to JavaScript, and JavaScript code to Swift. Inside a virtual machine (JSVirtualMachine) you can have multiple contexts, and you can pass data between them. ![]() This class is the actual environment (context) that executes your JavaScript code. On the other hand, the class that you’ll be dealing the most with, is JSContext. It’s possible to have multiple virtual machines running in an app, but they cannot exchange any data directly. In the JavaScriptCore framework, the JSVirtualMachine class represents programmatically that virtual machine, but usually you won’t have to deal directly with it. First off, JavaScript execution has its own environment, or to put it in a better way, a virtual machine where it runs into. Now that you feel the excitement too, let me underline a few necessary technical details. Of course, you can think more than the above, but even these are good reasons to make you want to get started with JavaScript in iOS. You are curious enough and you want to use JavaScript in your iOS projects.You could possibly make your app more flexible and powerful.Be careful though, because it’s easy to end up with a disaster. In that case the JavaScript code resides on a server and not locally in the app’s bundle. You want to modify the behaviour of your app remotely.It’s possible that some tasks are easier to be handled in JavaScript. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |