Objective-C 中的实例消息错误,这是什么意思?为什么会发生这种情况?
我收到以下错误或没有明显原因,我会尝试自己修复它,但我无法理解它的含义。还有人明白吗?这是错误,下面是代码。
错误:接收器类型“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的问题是
NSData
不响应EncryptAES:
选择器。您只能调用类中存在的选择器。利用 Objective-C 运行时的松散类型,您还可以在不响应所述选择器的类上调用选择器,只要该选择器出现在编译器正在使用的至少一个其他类的实现中即可。所有标准的 NSData 方法都可以在 NSData 类参考。 Apple 有加密示例代码,但它不是内置于
NSData
中的。The problem here is that
NSData
does not respond to theEncryptAES:
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 toNSData
.我的猜测是,您正在尝试对 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.