0

I'm trying to run this library from a .swift file. The sample code includes this snippet:

#import <XMLHTTPRequest/XMLHTTPRequest.h>

...

JSContext *jsContext = [JSContext new];
XMLHttpRequest *xmlHttpRequest = [XMLHttpRequest new];
[xmlHttpRequest extend:jsContext];

I believe this is Objective-C. How can I run that same code given that I have a .swift file?

MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
  • 1
    You should put it in an objective-C file, then create a bridging header for your project and import it there. This will expose it to your Swift project and you can use it regularly like you would any Swift class. – Fred Faust Jan 17 '17 at 15:04
  • Seems like you didn't pay enough attention to the question. Notice that thread (which I looked up previously) is asking how to call Objective-C from XCode. I said all I have is a `.swift` file, not a XCode project. That answer doesn't apply. This is, thus, not a duplicate. – MaiaVictor Jan 17 '17 at 15:18
  • You didn't say that you weren't using Xcode in your question. You can't call Objective-C from a plain `.swift` file, what you are asking is not possible. You need to compile it into a binary at the very least using Xcode, or clang from the command line. See [Compiling and linking Swift plus Objective C code from the OS X command-line](http://stackoverflow.com/q/24131476/2415822). – JAL Jan 17 '17 at 15:24

0 Answers0