xcode - 遇到运行时错误 "attempt to insert nil object "

标签 xcode swift gkmatchmaker

我正在尝试使用 Xcode 7 beta 5 编写一个简单的多人 Swift 程序。我在运行时遇到以下错误:

[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack

然后我试错了,发现这段代码不知何故引入了这个错误:

func setupMatchHandler() {
    /* This function handles invite as sent by other users */

    GKMatchmaker.sharedMatchmaker().matchForInvite(GKInvite().self , completionHandler: { (invitedMatch , invitationError) -> Void in

        if invitationError != nil {
            // error out
            print("Game Center error: \(invitationError)")
        }

        if invitedMatch != nil {
            // success
            print("invitation received!")
        }
    })

}

我想知道这里的任何专家都可以阐明这里出了什么问题吗?一百万!

山姆

最佳答案

也许检查 (GKInvite().self != nil) 会有帮助?

看来您唯一通过 matchForInvite 插入的就是这个

关于xcode - 遇到运行时错误 "attempt to insert nil object ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32155120/

相关文章:

ios - UITableViewCell 错误 : this class is not key value coding-compliant

Xcode 6.1 对 git 的表现很奇怪

ios - Xcode 6 和 Swift 中的 View 之间类似 Snapchat 的滑动导航)

ios - Xcode 5//iOS 6 和 7//TDD : OCUnit or XCTest

ios - 从 url 下载 pdf 文件

ios - 从解析中检索到的数据顺序

ios - 在navigationBar中设置rightBarButtonItem

ios - 在 Swift 中设置 GKMatchmakerViewControllerDelegate 时出现错误吗?

ios - 仅在 Gamecenter 中使用自动匹配

ios - 使用 monogame 构建默认 iOS 解决方案时出现错误消息