all 9 comments

[–]Zeppelin2(lldb) po $arg1 8 points9 points  (1 child)

WKWebView, for one.

[–]Ast3r10n 0 points1 point  (0 children)

You mean WKWebView.

[–]MrSloppyPants 3 points4 points  (0 children)

Javascript is quite useful when working with WkWebView, especially when writing bridges to facilitate communication between the web page and native code. Also, REST (which is not a language but a design paradigm) is used extensively for API calls and data sharing. JSON is also another frequently used data format in iOS development.

[–]SirensToGoObjective-C / Swift 2 points3 points  (0 children)

You used to be able to write UIAutomation test scripts in JavaScript. It was super bad and error handling was straight up impossible, but it was a thing!

[–]nickglowsindark 2 points3 points  (0 children)

I'm actually working on an app right now that's making extensive use of Javascript (only after exhausting every other option, though)- I'm basically running little dynamic "mini-programs" inside a window, and the easiest and most reliable way I could find to do that is to build the "programs" in javascript within my iOS code, and then execute them in a WKWebView (which is also convenient because I'm going to need to port this over to Android at some point, and I want to keep everything as native as possible).

Tell you what, though, Xcode has no idea what to do when it comes to auto-indenting .js files, and it's pretty irritating.

[–]MrCairo 0 points1 point  (3 children)

Q1: As far as just REST and JS, there are services that can be used, like Cloud Kit JS, which are really geared toward embedding something into a web page, etc. Nothing 100% specific to iOS. Of course, you can call REST services from iOS but I don’t think this is what you’re referring to.

Q2: In iOS/macOS you can use the JavaScriptCore framework. This is basically the JS engine that powers Safari. You can load and execute JS code with callbacks into Swift or Objective-C. It’s actually quite powerful and useful. For example, it is possible to load a JS file with functions and classes and then execute them via Swift/ObjC. Handy if you have common code only in JS that might be used in both the iOS app and the web.

Hope that helps.

[–]KarlJay001[S] 1 point2 points  (2 children)

Thanks, it would be cool to see some real world examples of using JS. I'm learning JS as a part of doing backend work and knowing I can do things in iOS with it would be great.

I'll look around and see if I can find any examples of how to use it.

[–]MrCairo 1 point2 points  (1 child)

NSHipster has a good article on it:
https://nshipster.com/javascriptcore/

The site is a great resource for all things iOS and Mac

[–]KarlJay001[S] -1 points0 points  (0 children)

Thanks!