简体   繁体   English

如何在 Swift 中添加 RNCryptor

[英]How to add RNCryptor in Swift

import Foundation
import Cocoa
import RNCryptor.h // this line give me problem

I am new to Swift and I want to work with encryption.我是 Swift 的新手,我想使用加密。 When I add RNCryptor I get an error saying "module not found".当我添加 RNCryptor 时,我收到一条错误消息,提示“找不到模块”。

I assume you're performing a manual install (rather than Carthage or Cocoapods).我假设您正在执行手动安装(而不是 Carthage 或 Cocoapods)。 Your import RNCryptor.h is in the wrong place.您的import RNCryptor.h位于错误的位置。 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).如果您已有桥接头文件,请添加#import "RNCryptor.h" (或复制 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. Swift 项目:在目标的构建设置中,将“Objective-C Bridging Header”设置为 RNCryptor.h 的路径。 (Or create a bridiging header and follow instructions above.) (或者创建一个桥接标题并按照上面的说明进行操作。)

    • ObjC project: Xcode will ask if you want to create a bridging header. ObjC 项目:Xcode 会询问您是否要创建桥接头。 Allow it to, and add #import "RNCryptor.h" to the header (or the path to which you copied RNCryptor.h)允许它,并将 #import "RNCryptor.h" 添加到标题(或您复制 RNCryptor.h 的路径)

The import "RNCryptor.h" goes in your bridging header, not your Swift code. import "RNCryptor.h"位于您的桥接头中,而不是您的 Swift 代码中。

If you're new to Swift, however, I would encourage you to look into CocoaPods to bring in your dependencies.但是,如果您不熟悉 Swift,我鼓励您研究 CocoaPods 以引入您的依赖项。 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.当我写那些鼓励你手动安装 RNCryptor 的文档时(我是 RNCryptor 中的“RN”),我不是 CocoaPods 的粉丝,但我逐渐相信它是 Cocoa 开发的重要组成部分,值得学习。 I now use it on all my new projects.我现在在我所有的新项目中都使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM