我有點誤解如何正確使用 - (void)。每當我嘗試使用 - (Void)編寫代碼,但出現錯誤「Expected declaration
」或有時「Binary operator '-' cannot be applied to operands of type 'UIFont' and '(Void).Type'
」。如何解決Swift中的「預期聲明」錯誤?
這是怎麼發生的?在swift中正確使用此功能的正確方法是什麼?
{
- (Void)keyboardWillShow { //>> showing me the error "Binary operator '-' cannot be applied to operands of type 'UIFont' and '(Void).Type'"
// Animate the current view out of the way
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
}
感謝
請通讀了雨燕編程語言[Apple的文檔(https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/index.html)。 –
用導致問題的實際代碼更新您的問題。 – rmaddy
這是Objective-C代碼,而不是Swift代碼。請閱讀[Swift編程語言](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/)書。 – rmaddy