繁体   English   中英

如何 - (void) 在 swift 代码中翻译

[英]How does - (void) translate in swift code

我在关于如何实现 Game Center 成就的苹果文档中看到了这段代码。 但我不太明白“- (void)”的真正含义以及如何在课堂上使用它。

- (void) challengeViewController:(MyAchievementChallengeViewController*)controller wasDismissedWithChallenge:(BOOL)issued
{
    [self dismissViewControllerAnimated:YES completion:NULL];
    if (issued)
    {
        [controller.achievement issueChallengeToPlayers:controller.players message:controller.message];
    }
}

有人可以向我解释在这种情况下使用关键字 void 吗?

在Objective-C中,函数的返回类型在函数名的前面。 所以(void)是返回类型。

所以 Obj-C - (void) myFunc在 Swift 中等价于func myFunc() -> Void或者-> Void可以简单地省略以获得func myFunc()

该功能将转化为

func challengeViewController( _ controller: MyAchievementChallengeViewController, wasDismissedWithChallenge challenge: Bool) {

}

这意味着该函数没有返回值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM