1

My goal is to create ssh connection between my iPhone and my raspberry pi. I installed this framework by using pods. That was successful, but here comes the problem. https://github.com/NMSSH/NMSSH

This page writes the following: Add #import NMSSH/NMSSH.h> to your source file.

But what is my souce file? Where should I place this import?

I can insert it into a swift file and when I placed it into an an objective-c file, I got NMSSH/NMSSH.h file not found.

What is the solution?

Thanks

Marci
  • 427
  • 2
  • 9
  • 20
  • If you are working inside a Swift project, you need to put that import statement into an [objective-c bridging header](https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) file. – LinusGeffarth Dec 01 '17 at 20:02
  • Thanks, that threw no error. And if that is done, where should I write my code that uses nmssh. I mean, should I import something in ViewController.swift? Thanks – Marci Dec 01 '17 at 20:04
  • You shouldn't have to. Just write your code :) – LinusGeffarth Dec 01 '17 at 20:07
  • NMSSHSession *session = [NMSSHSession connectToHost:@"127.0.0.1:22" withUsername:@"user"]; I pasted this line in ViewController.swift into the viewDidLoad function but I got Expected expression in container loteral, consecutive statements on a line must be seperated by ;, expected , separator. Do you think this should run without error or should just this code be upgraded? Thanks – Marci Dec 01 '17 at 20:14
  • That's objective-c code, though, no Swift. It should probs look sth. like this: `let session: NMSSHSession = NMSSHSession.connectToHost(url: "", username: "")` – LinusGeffarth Dec 01 '17 at 20:16

1 Answers1

2

If you are working inside a Swift project, you need to put that import statement into an objective-c bridging header file.
Check out Apple's documentation on bridging headers.

Also, you need to write the equivalent Swift code, instead of the code examples on the Github page.

LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
  • My very last question: How can I know the expressions in swift for this library. For example: [session authenticateByPassword:@"pass"]; What is this in swift? Or am I supposed to code in objective-c when using this library? Thanks – Marci Dec 01 '17 at 20:32
  • No problem. Probably: `session.authenticate(password: "")`. But that really depends on what they chose to name it. – LinusGeffarth Dec 01 '17 at 20:34
  • Is it well-documented anywhere or you just know it from experience? Thx – Marci Dec 01 '17 at 20:36
  • Nope, sorry. I have tried the library a few weeks ago but then changed my approach so I didn't bother using it / researching on it anymore. – LinusGeffarth Dec 01 '17 at 20:36
  • What did you change it to? – Marci Dec 01 '17 at 20:37
  • Oh I figured I didn't actually have to connect to my server to read the database (which sounds really dumb to anyone w/ server / database experience), ha. That probably doesn't help you, though. – LinusGeffarth Dec 01 '17 at 20:38
  • Sorry for disturbing you, but I get "NMSSH/NMSSH.h not found again". The other error is failed to emit precompiled header and it continues with the path of the bridging header file. I created another project and installed pods again but I have those two errors again. Do you have any idea how to solve it? Thanks – Marci Dec 05 '17 at 22:14
  • So the new error is in the new project? Have you setup the bridging header from inside the project or just copied the file in? Check the build settings (search for bridging header) for the header’s path. It needs to be correct. – LinusGeffarth Dec 06 '17 at 05:54