Objective-C 中的实例消息错误,这是什么意思?为什么会发生这种情况?

发布于 2024-12-09 23:36:20 字数 537 浏览 1 评论 0原文

我收到以下错误或没有明显原因,我会尝试自己修复它,但我无法理解它的含义。还有人明白吗?这是错误,下面是代码。

错误:接收器类型“NSdata”例如消息未声明选择器类型“EncryptAES:”的方法

我已在包含错误的行中添加了注释:

//Change the Input String to Data
NSData *objNSData = [NSData dataWithData:[Input dataUsingEncoding: NSUTF8StringEncoding]];
//Encrypt the Data
[objNSData EncryptAES:Keyword.text]; //Error appears here
NSString *InputString = [[NSString alloc] initWithData:objNSData encoding:NSUTF8StringEncoding];

这是什么意思,为什么是它发生了,我能做些什么来解决它?

而且,什么是实例消息?

I get the below error hor no apparent reason, I would try to fix it myself but I can't understand what it means. Does anyone else understand it? Here is the error and below it is the code.

Error: Receiver Type 'NSdata' for instance message does not declare a method with selector type 'EncryptAES:'

I have added a comment to the line with the error on it:

//Change the Input String to Data
NSData *objNSData = [NSData dataWithData:[Input dataUsingEncoding: NSUTF8StringEncoding]];
//Encrypt the Data
[objNSData EncryptAES:Keyword.text]; //Error appears here
NSString *InputString = [[NSString alloc] initWithData:objNSData encoding:NSUTF8StringEncoding];

What does this mean, why is it happening and what can I do to fix it?

And, what is an instance message?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何以笙箫默 2024-12-16 23:36:20

这里的问题是 NSData 不响应 EncryptAES: 选择器。您只能调用类中存在的选择器。利用 Objective-C 运行时的松散类型,您还可以在不响应所述选择器的类上调用选择器,只要该选择器出现在编译器正在使用的至少一个其他类的实现中即可。

所有标准的 NSData 方法都可以在 NSData 类参考。 Apple 有加密示例代码,但它不是内置于 NSData 中的。

The problem here is that NSData does not respond to the EncryptAES: selector. You can only invoke selectors that exist on the class. With the Objective-C runtime's loose typing, you can also invoke a selector on a class that does not respond to said selector, as long as the selector appears in the implementation of at least one other class that the compiler is working with.

All standard NSData methods can be found on the NSData Class Reference. Apple has sample code for encryption, but it is not built-in to NSData.

是你 2024-12-16 23:36:20

我的猜测是,您正在尝试对 NSData 使用 AESEncrypt“类别”,但实际上您的项目中并未安装该类别。

My guess is that you're trying to use the AESEncrypt "category" for NSData, but you don't actually have the category installed in your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文