{"id":10540,"date":"2015-01-20T11:03:58","date_gmt":"2015-01-20T16:03:58","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=10540"},"modified":"2015-01-20T11:03:58","modified_gmt":"2015-01-20T16:03:58","slug":"javascriptcore","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/01\/20\/javascriptcore\/","title":{"rendered":"JavaScriptCore"},"content":{"rendered":"<p><a href=\"http:\/\/nshipster.com\/javascriptcore\/\">Nate Cook<\/a>:<\/p>\n<blockquote cite=\"http:\/\/nshipster.com\/javascriptcore\/\">\n<p>We can easily access any values we&rsquo;ve created in our <code>context<\/code> using subscript notation on both <code>JSContext<\/code> and <code>JSValue<\/code> instances. <code>JSContext<\/code> requires a string subscript, while <code>JSValue<\/code> allows either string or integer subscripts for delving down into objects and arrays:<\/p>\n<\/blockquote>\n<p>Swift doesn&rsquo;t support the subscript notation, though.<\/p>\n<blockquote cite=\"http:\/\/nshipster.com\/javascriptcore\/\">\n<p>With a <code>JSValue<\/code> that wraps a JavaScript function, we can call that function directly from our Objective-C\/Swift code using Foundation types as parameters. Once again, JavaScriptCore handles the bridging without any trouble[&#8230;]<\/p>\n<p>[&#8230;]<\/p>\n<p>There are two main ways of giving a <code>JSContext<\/code> access to our native client code: blocks and the <code>JSExport<\/code> protocol.<\/p>\n<p>[&#8230;]<\/p>\n<p>Since blocks can capture references to variables and <code>JSContext<\/code>s maintain strong references to all their variables, some care needs to be taken to avoid strong reference cycles. Avoid capturing your <code>JSContext<\/code> or any <code>JSValue<\/code>s inside a block. Instead, use <code>[JSContext currentContext]<\/code> to get the current context and pass any values you need as parameters.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Nate Cook: We can easily access any values we&rsquo;ve created in our context using subscript notation on both JSContext and JSValue instances. JSContext requires a string subscript, while JSValue allows either string or integer subscripts for delving down into objects and arrays: Swift doesn&rsquo;t support the subscript notation, though. With a JSValue that wraps a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[31,469,346,30,475,54,71,901],"class_list":["post-10540","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios7","tag-javascript","tag-mac","tag-mavericks","tag-objective-c","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=10540"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10540\/revisions"}],"predecessor-version":[{"id":10541,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10540\/revisions\/10541"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=10540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=10540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=10540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}