在目标 C 中打印变量

Vee*_*jay 1 xcode objective-c ios

我正在尝试将这个应用程序“说”的单词打印到控制台上,以便我可以将它存储在一个变量中以备后用。函数就像这样,我试图打印变量“word”中的内容。我该怎么办?

- (void)speak:(NSString *)words {
  if ([synth isSpeaking]) {
      NSLog(words);
    return;
  }
  AVSpeechUtterance *utterance =
      [AVSpeechUtterance speechUtteranceWithString:words];
  utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
  utterance.rate = 0.75 * AVSpeechUtteranceDefaultSpeechRate;
  [synth speakUtterance:utterance];

}
Run Code Online (Sandbox Code Playgroud)

我试图在那里添加 NSLog(words),因为我认为这是解决这个问题的方法。但是,我收到一个错误,这不起作用。我将它添加到上面的代码块中只是为了清楚地说明我所做的。

小智 5

NSLog(@"words :: %@", words);
Run Code Online (Sandbox Code Playgroud)

或者

在控制台选项卡打印

 po words
Run Code Online (Sandbox Code Playgroud)

  • 请花时间发布正确的代码。Objective-C 区分大小写。 (7认同)
  • 不是`nslog`而是`NSLog` (2认同)