如何将此GKVoiceChat代码迁移到Swift?

时间:2015-03-08 13:51:06

标签: ios swift game-center

我想将以下创建游戏中心GKVoiceChat的代码迁移到Swift中:

GKMatch* match;
GKVoiceChat *teamChannel = [[match voiceChatWithName:@"redTeam"] retain];
GKVoiceChat *allChannel = [[match voiceChatWithName:@"allPlayers"] retain];

我怀疑Swift代码看起来像这样:

var match: GKMatch!
func voiceChatWithName(name: String!) -> GKVoiceChat! {
    return nil
}

但即使我搜索了文档,我也完全不知道它在Swift中是如何工作的。如何将上面的代码迁移到Swift?

1 个答案:

答案 0 :(得分:1)

因此,在您的GKMatchmakerViewControllerDelegate方法中,您应该能够执行以下操作:

func matchmakerViewController(_ viewController: GKMatchmakerViewController!,
                      didFindMatch match: GKMatch!) {

    let teamChannel = match.voiceChatWithName("redTeam")
    let allChannel = match.voiceChatWithName("allPlayers")

    // use the channels above
}