Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c (void)如何在swift代码中翻译_Objective C_Swift_Function_Game Center - Fatal编程技术网

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

Objective c (void)如何在swift代码中翻译,objective-c,swift,function,game-center,Objective C,Swift,Function,Game Center,我在苹果公司关于如何实现游戏中心成就的文档中发现了这段代码。但我不太明白“-(void)”到底是什么意思,以及我如何在课堂上使用它 - (void) challengeViewController:(MyAchievementChallengeViewController*)controller wasDismissedWithChallenge:(BOOL)issued { [self dismissViewControllerAnimated:YES completion:NULL]

我在苹果公司关于如何实现游戏中心成就的文档中发现了这段代码。但我不太明白“-(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) {

}

非常感谢你,只要现在对我有意义。我刚开始学习Swift和SwiftUI,我一直在努力学习苹果文档。这很有帮助。下一步是找出
void*
的含义