قالب وردپرس درنا توس
Home / IOS Development / JavaScriptCore – NSHipster

JavaScriptCore – NSHipster



According
this ranking of programming popularity,
Swift and Objective-C are back to the back around 10th position –
A solid display for both languages, all taken into account.
… that is, unless you consider how they are tied for 2nd and 3rd place
among the languages ​​allowed on iOS, their most popular platform.

Whether you love it or hate it,
JavaScript has become the most important language for developers today.
Despite any effort, we can take to change or replace it
We would be hard pressed to deny their benefit.

This week at NSHipster,
we will discuss the JavaScriptCore framework,
and how to use it to set aside
Your core believes in the type of safety and type of health
and allow JavaScript to do some of the heavy lifting in your apps.


The JavaScriptCore framework provides
Direct access to WebKit's JavaScript engine in your apps.

You can execute JavaScript code in a context
by calling evaluate Script (_ :) method on a JSContext object.
scripts (_ :) returns a JSValue item
contains the value of the last expression evaluated.
For example,
a JavaScript expression that adds numbers 1

, 2 and 3
results in the number value 6.

  import    Java  Script  Core 

  la    context    =    JSContext   () ! 
 ] ]      =    context .  
  result  ] .   to  Int32   ()    // 6 

You can cast JSValue into a native Swift or Objective-C type
by calling the corresponding method found in the following table:

A JSValue object

JavaScript Type JSValue method Objective-C Type Swift Type
] string to string NSString string!
boolean to boolean BOOL boolean
number to number
to Double
to Int32
] to uint32
NSNumber
double
int32_t
uint32_t
NSNumber!
Int32
uint32
Date to Date NSDate date?
Array to Array NSArray [Any]
Object to Dictionary NSDictionary [Any Hashable: Any] !
Class to Object
to item to class:
cus tom type custom type JavaScript type Evaluation is not limited to single sentences.
When evaluating code declaring a function or variable,
]
# 19659023]



function triple (number) {
return number * 3;


Source link