On a tutorial from youtube tried to make multiplayer. Everything works, but there is only one problem. In the line let messageDict = ["coins":button.tag]
I transfer to the 2nd device a "message" by tag, but any other coin disappears, but not the one that was clicked on 1 device. How to make that coin disappear on the 2nd device, which was credited on the 1st device? Here is the code.
@IBAction func coinsHidden(button: UIButton) { button.hidden = true button.tag = 1 coins = coins.filter({ !$0.hidden }) let messageDict = ["coins":button.tag] // вот это строчка ключевая do { let messageData = try! NSJSONSerialization.dataWithJSONObject(messageDict, options: NSJSONWritingOptions.PrettyPrinted) let error:NSError? try! appDelegate.mpcHandler.session.sendData(messageData, toPeers: appDelegate.mpcHandler.session.connectedPeers, withMode: MCSessionSendDataMode.Reliable) } } //multiplayer func handleReceivedDataWithNotification(notification:NSNotification){ let userInfo = notification.userInfo! as Dictionary let receivedData:NSData = userInfo["data"] as! NSData do { let message = try! NSJSONSerialization.JSONObjectWithData(receivedData, options: NSJSONReadingOptions.AllowFragments) as! NSDictionary let senderPeerId:MCPeerID = userInfo["peerID"] as! MCPeerID let senderDisplayName = senderPeerId.displayName if message.objectForKey("string")?.isEqualToString("New Game") == true{ let alert = UIAlertController(title: "Coin", message: "\(senderDisplayName) has started a new Game", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) }else{ let field:Int? = message.objectForKey("coins")?.integerValue coins[field!].hidden = true coins = coins.filter({ !$0.hidden }) } } }