iOS Swift Tutorial: Simple Multiplayer Game – Tic Tac Toe

In this tutorial you are going to use the Multipeer Connectivity Framework to create a multiplayer Tic Tac Toe game. The Multipeer Connectivity Framework allows you to connect and share data with devices nearby.



If you have questions about the video or Cocoa programming. Please comment below.



Usha Natarajan says:

Brian, Fantastic Tutorial. Very detailed explanation and easy to follow instructions. I got stuck at a couple of places ’cause i was trying to adapt it for Swift 3.0 but, once those issues were sorted, it was smooth sailing. Works like a charm. Thanks.

Kinpil says:

Why 1 hour!?

Dave Priva says:

Do you know any tutorial which shows how to make tic tac toe or something similar which will be using internet connection?

Alikhan Nathoo says:

I want to integrate bluetooth in my app like the music player app that comes with the iphone. How do Implement the same bluetooth code, so that the audio that comes out of my app will play in the bluetooth speaker. I got the app to play from the iphone speaker, the headphone jack, BUT NOT the bluetooth speaker. I thought it would play through the bluetooth speaker but the music doesnt, it only works through the headhphone jack and the iphone

itsmeagain says:

Thanks for your tutorials, I’ve learnt so much from them. Do you have any plans of making a similar tutorial with the Game Center network approach in Swift? I’ve searched all over the web for a tutorial in Swift using the internet approach but I haven’t got anything.

Flix Maaß says:

When checking the results you could also do something like this:

if fields[0].player == fields[1].player == fields[2].player {
Winner = fields[0].player

Then you don’t have to do each combination twice ✌️

Jura1704 says:

Hi Brian, Great tutorial. Thanks. Regarding to the final solution / homework, my solution is : After field tapped set all fields to userInteractionEnable = false and when receiving data from second device set all empty fields to userInteractionEnable = true – and this simple solution control the right turn and also prevent tapping already used field.

func userInteraction(enable:Bool){
for index in 0 … fields.count – 1 {
if fields[index].player == “” || fields[index].player == nil{
if enable == false {
fields[index].userInteractionEnabled = false
print(index, enable)
fields[index].userInteractionEnabled = true
print(index, enable)
Regards, JureX

Dhanraj Kawade says:

Your awesome brian…

Anand Mukut Tirkey says:

I’m unable to connect my simulator with real device ( iPad 2)
Please help

sainath reddy says:

what is the version of Xcode you are using, i tried to open the tutorial files i got many errors please give the solution to run your files, currently aim using Xcode 7.3.1

Mahbod Taba says:

how can I fix it:
let message = NSJSONSerialization.JSONObjectWithData(receivedData, options: NSJSONReadingOptions.AllowFragments, error: nil) as NSDictionary

extra argument error??????????????????/

Scott Linder says:

Is it possible to implement MCBrowserViewControllerDelegate with GameViewController class instead of ViewController class?

Andrew says:

Hey Brian what School do u recommend for swift and ios app development

Max Schellenberg says:

This tutorial is out of date.

I even tried downloading the Xcode files and converting them but it there were too many errors left to be functional.

Nitish Kumar says:

how can i check mutiplayer activity if i don’t have any device , is there any way

Viro Science says:

it isn’t working for me some updates f*cked shit up and I can’t fix it HELP

Anne M says:

Very interesting but very difficult to follow in swift2, especially try and catch errors that I am not sure how to implement. Had to give up after 2/3.
Would you consider upgrading your tutorial?

Jesse Burris says:

Awesome tutorial. Haven’t been able to find another like it, or book on MultipeerConnectivity framework development. Thank you so much. Has given me a fast start in developing multiplier apps.

yi apps says:

Hi. How to remove the errors? Thanks.

Jeylani Osman says:

Extra argument ‘error’ in call

james stone says:

Great tutorial, but one problem. In TTTImageView.swift I keep getting the error “Method ‘setPlayer’ with Objective-C selector ‘setPlayer:’ conflicts with setter for ‘player’ with the same Objective-C selector” Please help! (I am using Xcode 8.4 and swift 1.2)

valerio pavan says:

Thanx a lot Brian! Great tutorial! :)

Hu Bong says:

Why did you not create a method for the big code in “checkResult”. Then you can less Code and more overview. :)

mmiirr66 says:

I keep getting the error “Extra argument ‘ error’ in call” in: func handleReceivedDataWithNotification(notification:NSNotification as well as: func fieldTapped (recognizer:UITapGestureRecognizer). I have no idea how to fix that. I would appreciate any help!!! thanks for the video

Syed Ali Hussain Rizvi says:

can u help me with multipeer connectivity sharing camera view “??

Adam Cai says:

Can you make this for Swift 2.0?

Ten Box says:

You could mirror your device using quicktime, just start a movie recording, connect your device to your mac with a lightning cable and press the little arrow near the record button, selecting your device.

Jai Khanna says:

I am able to send the data successfully, but the control doesn’t go into the ‘handleReceivedDataWithNotification’ function. So, I’m not able to receive the data anywhere. Anyone having a similar issue?

Virus says:

it’s really help me….. thanks

Russell Morgan says:

Brian, This is a splendid tutorial. I was having so many issues with intermittently dropped connections with every other approach I had followed, and your tutorial sorted everything out for me! I was able to build and release the four letter word game I had been meaning to develop for ages, and I couldn’t have done it without your help.

Abhishek Gupta says:

can anyone upload the Swift 2.0 compatible Xcode project of the same.. @Brian Advent

D Chu says:

This is really nice show. In about one hour I learned iOS Multipeer Connectivity Framework. Thank you Brian!

Kidzeegames says:

one of the best video i have seen

Mukund Agarwal says:

Thank you for the great tutorial.
In case other people are running into the same issue then please use this updated code for ViewController.swift->fieldTapped function for xCode 7.1.1 onwards: func fieldTapped (recognizer: UITapGestureRecognizer){
let tappedField = recognizer.view as! TTTImageView

let messageDict = [“field”:tappedField.tag, “player”:currentPlayer]

do {
let messageData = try NSJSONSerialization.dataWithJSONObject(messageDict, options: NSJSONWritingOptions.PrettyPrinted)

do {
try appDelegate.mpcHandler.session.sendData(messageData, toPeers: appDelegate.mpcHandler.session.connectedPeers, withMode: MCSessionSendDataMode.Reliable)
}catch let error2 as NSError {
print(“json error2: (error2.localizedDescription)”)
} catch let error as NSError {
print(“json error: (error.localizedDescription)”)

//Todo: checkResults

Cr Ransom says:

Hi I am trying to follow along however I have a problem with code the TTTUIview

import UIKit

class TTTImageView: UIImageView {

var player:String?
var activated: Bool! = false

func setPlayer [_player1String]{
self.player = _player
if activated == false{
if _player == “x”
self.image = UIImage(named: “x”)
self.image = UIImage(named: “o”)
activated = true

the func setPlayer [_player1String]{ is giving me an expected declaration error. What am I missing?

אורי רינת says:

?who can i get the code of all this program

Dylan Bautista says:


I now more than toRaw () puts me because RawValue ?

I said to have been replaced

How do I fix it ?

sainath reddy says:

hi am getting error in this line

let message = NSJSONSerialization.JSONObjectWithData(receivedData, options: NSJSONReadingOptions.AllowFragments, error: nil) as NSDictionary

error is Extra argument ‘error’ in call

i am not able to resolve this error please give me solution

Aviral Gupta says:

When I try to run the app it quits after connecting to another device or after playing a turn. Any suggestions?

Константин Попов says:

Hi! I can’t download the tutorial files. Please, fix this problem. Or can you send this files on my e-mail, please Thanks a lot!

mark lucking says:

Brian, this tutorial made me smile 2 minutes into it, playing with yourself and wanting to win! The most watchable programming tutorial I have ever watched, a difficult subject and my third tutorial I tried to master MPC and finally I find something that is I kid you not is inspirational. I hope you do this for a living, cause you are very good at it.

Max Schellenberg says:

could you please remake this for swift 3?

Write a comment


Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.

Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours