在RedMonk发布的2015年1月编程语言排行榜中,Swift采纳率排名迅速飙升,从刚刚面世时的68位跃至22位,Objective-C仍然稳居TOP 10,而JavaScript则凭借着其在iOS平台上原生体验优势成为了年度最火热的编程语言。
X和iOS系统等高速虚拟机也蓬勃发展起来。
jscontext/JSValue
jscontext即JavaScript代码的运行环境。一个Context就是一个JavaScript代码执行的环境,也叫作用域。当在浏览器中运行JavaScript代码时,jscontext就相当于一个窗口,能轻松执行创建变量、运算乃至定义函数等的JavaScript代码:
- //Swift
- let context = jscontext()
- context.evaluateScript("var num = 5 + 5")
- context.evaluateScript("var names = ['Grace','Margaret']")
- context.evaluateScript("var triple = function(value) { return value * 3 }")
- let tripleNum: JSValue = context.evaluateScript("triple(num)")
JSValue包含了一系列用于获取Underlying Value的方法,如下表所示:
- NSLog(@"Tripled: %d",[tripleNum toInt32]);
- // Tripled: 30