候选者具有非匹配类型的协议

时间:2015-02-07 02:37:07

标签: ios swift gamekit

我试图创建模拟对象来测试一些与GameKit相关的代码。在尝试了几条路线之后,我决定为GKTurnBasedMatch&编写协议。 GKTurnBasedParticipant。当我尝试在另一个协议中引用一个协议时,一切似乎都在工作

@objc protocol Participant {
    var player: GKPlayer! { get }
    var lastTurnDate: NSDate! { get }
    var status: GKTurnBasedParticipantStatus { get }
}

extension GKTurnBasedParticipant : Participant { }

@objc protocol Match {

    var matchID: String! { get }
    var creationDate: NSDate! { get }
    var participants: [AnyObject]! { get } // array of GKTurnBasedParticipant objects
    var status: GKTurnBasedMatchStatus { get }

    // *was* GKTurnBasedParticipant!
    var currentParticipant: Participant! { get }

    var matchData: NSData! { get }
    var message: String! { get }

    func loadMatchDataWithCompletionHandler(completionHandler: ((NSData!, NSError!) -> Void)!)
    func endTurnWithNextParticipants(nextParticipants: [AnyObject]!, turnTimeout timeout: NSTimeInterval, matchData: NSData!, completionHandler: ((NSError!) -> Void)!)
    func saveCurrentTurnWithMatchData(matchData: NSData!, completionHandler: ((NSError!) -> Void)!)
}

extension GKTurnBasedMatch : Match { }

我需要能够返回模拟参与者,似乎我可以说currentParticipant返回Participant个对象而不是GKTurnBasedParticipant,看看如何后者实施协议。

但它不会编译,声称:

.../GameKit+protocols.swift:51:1: error: type 'GKTurnBasedMatch' does not conform to protocol 'Match'
extension GKTurnBasedMatch : Match { }
^
.../GameKit+protocols.swift:28:6: note: protocol requires property 'currentParticipant' with type 'Participant'
        var currentParticipant: Participant! { get }
            ^
GameKit.GKTurnBasedMatch:8:13: note: candidate has non-matching type 'GKTurnBasedParticipant!'
  @objc var currentParticipant: GKTurnBasedParticipant! { get }
            ^

注意:我在这里查看了另一个candidate has non-matching type问题&虽然它是同一个错误,但它与我的问题无关。

0 个答案:

没有答案