一元表达式的无效参数类型'void' - Objective-C

时间:2015-10-12 07:18:39

标签: objective-c

代码:

NSSpeechRecognizer *recog = [[NSSpeechRecognizer alloc]init];

NSArray *cmds = [NSArray arrayWithObjects:@"Hello",@"I'm back",nil];

[recog setCommands:cmds];

[recog startListening];

- (void)recog:(NSSpeechRecognizer *)sender didRecognizeCommand:(NSString *)cmds

if ([(NSString *)cmds isEqualToString:@"hello"]) {
    NSLog(@"Hello to you too");
}

if ([(NSString *)cmds isEqualToString:@"I'm back"]) {
    NSLog(@"Welcome back, its good to see you");
}

错误消息:

  

无效参数类型'void'到一元表达式

2 个答案:

答案 0 :(得分:0)

            Your Method Is Wrong (replace (nsstring*)to (id) and also not add clossing breckets.


- (void)recog:(NSSpeechRecognizer *)sender didRecognizeCommand:(id)cmds
{
               if ([(NSString *)cmds isEqualToString:@"hello"]) 
               {
                [self performSelector:@selector(hello:)];//also u can handle responce.
                NSLog(@"Hello to you too");
               }

            if ([(NSString *)cmds isEqualToString:@"I'm back"]) 
               {
                 NSLog(@"Welcome back, its good to see you");
               }
 }

-(void)hello:(id)sender 
  {
            //Do stuff here...

   }

答案 1 :(得分:0)

您无法在方法中使用-声明实例方法。它认为你试图使用否定运算符否定方法声明,这是一元运算符。