使用MD5算法时出错
我正在尝试运行这个 MD5 算法,这是我在 stackoverflow 上的这篇文章。但我不断收到以下错误:
2010-08-06 14:45:40.971 Intel[3195:a0f] -[TaskController md5:]: unrecognized selector sent to instance 0x108df0
2010-08-06 14:45:40.973 Intel[3195:a0f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TaskController md5:]: unrecognized selector sent to instance 0x108df0'
*** Call stack at first throw:
(
0 CoreFoundation 0x9875abba __raiseError + 410
1 libobjc.A.dylib 0x96a3a509 objc_exception_throw + 56
2 CoreFoundation 0x987a78db -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x987017e6 ___forwarding___ + 950
4 CoreFoundation 0x987013b2 _CF_forwarding_prep_0 + 50
5 Intel 0x00003143 -[TaskController findFileOrCreateFile] + 709
6 Intel 0x00002d29 -[TaskController init] + 92
7 Intel 0x00002c03 main + 128
8 Intel 0x00002a6a start + 54
)
我虽然这可能与我的字符串是 UTF-8 有关,但我尝试输入以下字符串,但仍然收到错误:
NSString *foo = @"your text here";
const char *bar = [foo UTF8String];
有帮助吗?
非常感谢
I'm trying to run this MD5 algorithm, which I found on this post on stackoverflow . But I keep on getting the following error:
2010-08-06 14:45:40.971 Intel[3195:a0f] -[TaskController md5:]: unrecognized selector sent to instance 0x108df0
2010-08-06 14:45:40.973 Intel[3195:a0f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TaskController md5:]: unrecognized selector sent to instance 0x108df0'
*** Call stack at first throw:
(
0 CoreFoundation 0x9875abba __raiseError + 410
1 libobjc.A.dylib 0x96a3a509 objc_exception_throw + 56
2 CoreFoundation 0x987a78db -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x987017e6 ___forwarding___ + 950
4 CoreFoundation 0x987013b2 _CF_forwarding_prep_0 + 50
5 Intel 0x00003143 -[TaskController findFileOrCreateFile] + 709
6 Intel 0x00002d29 -[TaskController init] + 92
7 Intel 0x00002c03 main + 128
8 Intel 0x00002a6a start + 54
)
I though it might have something to do with my string being UTF-8, but I have tried inputting the following string and still get errors:
NSString *foo = @"your text here";
const char *bar = [foo UTF8String];
Any help?
Thanks so much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它与你的字符串格式没有任何关系。运行时正在寻找您的 md5 方法,但没有找到。您是否在 TaskController 对象的 @interface 部分中定义了它?您是否使用正确数量的参数定义/调用它?
It doesn't have anything to do with your string format. The runtime is looking for your md5 method and not finding it. Did you define it in your @interface section of your TaskController object? Did you define/call it with the right number of parameters?
读取异常信息:
您尝试向无法识别此类消息的实例发送
md5:
消息。这就是您尝试发送它的地方。
正如您在对 Wade Williams 的回答的评论中透露的那样,问题的原因是您已将该方法声明并定义为类方法 (
+[TaskController md5:]
)。请注意您的声明如何在异常显示 - 的情况下有一个 +;问题是不匹配。由于您将消息发送到 TaskController 实例,而不是 TaskController 类,因此解决方案过去和现在都是将声明更改为实例方法(
-[TaskController md5:]
,如异常消息所述) 。另一种解决方案是将其保留为类方法,并更改消息表达式以将消息发送到类而不是实例 (hash = [TaskController md5:str]
)。Read the exception message:
You tried to send an
md5:
message to an instance that does not recognize such messages.And this is where you tried to send it from.
As you revealed in your comment on Wade Williams's answer, the cause of your problem was that you had declared and defined the method as a class method (
+[TaskController md5:]
). Note how your declaration had a + where the exception shows a -; the problem is the mismatch.Since you were sending the message to a TaskController instance, not the TaskController class, the solution was and is to change the declaration to an instance method (
-[TaskController md5:]
, like the exception message says). The other solution would have been to leave it as a class method and change the message expression to send the message to the class rather than an instance (hash = [TaskController md5:str]
).