How to add RNCryptor in Swift

556 Views Asked by At
import Foundation
import Cocoa
import RNCryptor.h // this line give me problem

I am new to Swift and I want to work with encryption. When I add RNCryptor I get an error saying "module not found".

1

There are 1 best solutions below

0
Rob Napier On

I assume you're performing a manual install (rather than Carthage or Cocoapods). Your import RNCryptor.h is in the wrong place. Here are the relevant docs:

  • If you already have a bridging header file, add #import "RNCryptor.h" (or the path to which you copied RNCryptor.h).

  • If you don't have a bridging header:

    • Swift project: In your target's Build Settings, set "Objective-C Bridging Header" to your path for RNCryptor.h. (Or create a bridiging header and follow instructions above.)

    • ObjC project: Xcode will ask if you want to create a bridging header. Allow it to, and add #import "RNCryptor.h" to the header (or the path to which you copied RNCryptor.h)

The import "RNCryptor.h" goes in your bridging header, not your Swift code.

If you're new to Swift, however, I would encourage you to look into CocoaPods to bring in your dependencies. When I wrote those docs encouraging you to install RNCryptor by hand (I'm the "RN" in RNCryptor), I was not a fan of CocoaPods, but I've grown to believe it's an important part of Cocoa development and worth learning. I now use it on all my new projects.