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.
*** UDEMY SWIFT COURSE ***
https://www.udemy.com/start-developing-ios-apps-with-swift-for-beginners
*** TUTORIAL FILES ***
http://goo.gl/hPoKpo
***COMMENTS****
If you have questions about the video or Cocoa programming. Please comment below.
Web: http://www.prentis.de
Amazon Auto Links: No products found.
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.
Why 1 hour!?
Do you know any tutorial which shows how to make tic tac toe or something similar which will be using internet connection?
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
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.
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 ✌️
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)
}else{
fields[index].userInteractionEnabled = true
print(index, enable)
}
}
}
}
Regards, JureX
Your awesome brian…
I’m unable to connect my simulator with real device ( iPad 2)
Please help
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
how can I fix it:
let message = NSJSONSerialization.JSONObjectWithData(receivedData, options: NSJSONReadingOptions.AllowFragments, error: nil) as NSDictionary
extra argument error??????????????????/
Is it possible to implement MCBrowserViewControllerDelegate with GameViewController class instead of ViewController class?
Hey Brian what School do u recommend for swift and ios app development
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.
how can i check mutiplayer activity if i don’t have any device , is there any way
it isn’t working for me some updates f*cked shit up and I can’t fix it HELP
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?
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.
Hi. How to remove the errors? Thanks.
https://gyazo.com/80fddf3e80b3b8305a08b272692236bc
Extra argument ‘error’ in call
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)
Thanx a lot Brian! Great tutorial! 🙂
Why did you not create a method for the big code in “checkResult”. Then you can less Code and more overview. 🙂
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
can u help me with multipeer connectivity sharing camera view “??
Can you make this for Swift 2.0?
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.
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?
it’s really help me….. thanks
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.
can anyone upload the Swift 2.0 compatible Xcode project of the same.. @Brian Advent
This is really nice show. In about one hour I learned iOS Multipeer Connectivity Framework. Thank you Brian!
one of the best video i have seen
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
tappedField.setPlayerMove(currentPlayer)
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
}
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”)
}else{
self.image = UIImage(named: “o”)
}
activated = true
}
the func setPlayer [_player1String]{ is giving me an expected declaration error. What am I missing?
?who can i get the code of all this program
Hello,
I now more than toRaw () puts me because RawValue ?
I said to have been replaced
How do I fix it ?
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
When I try to run the app it quits after connecting to another device or after playing a turn. Any suggestions?
Hi! I can’t download the tutorial files. Please, fix this problem. Or can you send this files on my e-mail, please po_ko_vi4@mail.ru Thanks a lot!
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.
could you please remake this for swift 3?