Skip to content

Commit 107810b

Browse files
committed
update for latest version
1 parent 9b566fd commit 107810b

File tree

8 files changed

+172
-169
lines changed

8 files changed

+172
-169
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

Podfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use_frameworks!
2+
3+
target 'TicTacIOiOS' do
4+
pod 'Socket.IO-Client-Swift', '~> 11.1.3' # Or latest version
5+
end

TicTacIOiOS.xcodeproj/project.pbxproj

Lines changed: 90 additions & 99 deletions
Large diffs are not rendered by default.

TicTacIOiOS.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
11.3 KB
Binary file not shown.

TicTacIOiOS/AppDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313
var window: UIWindow?
1414

1515

16-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
16+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1717
return true
1818
}
1919

20-
func applicationWillResignActive(application: UIApplication) {
20+
func applicationWillResignActive(_ application: UIApplication) {
2121
}
2222

23-
func applicationDidEnterBackground(application: UIApplication) {
23+
func applicationDidEnterBackground(_ application: UIApplication) {
2424

2525
}
2626

27-
func applicationWillEnterForeground(application: UIApplication) {
27+
func applicationWillEnterForeground(_ application: UIApplication) {
2828
}
2929

30-
func applicationDidBecomeActive(application: UIApplication) {
30+
func applicationDidBecomeActive(_ application: UIApplication) {
3131

3232
}
3333

34-
func applicationWillTerminate(application: UIApplication) {
34+
func applicationWillTerminate(_ application: UIApplication) {
3535
}
3636

3737

TicTacIOiOS/SocketIOClientSwift

Lines changed: 0 additions & 1 deletion
This file was deleted.

TicTacIOiOS/ViewController.swift

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import UIKit
9+
import SocketIO
910

1011
class ViewController: UIViewController, UIAlertViewDelegate {
1112
@IBOutlet weak var btn0:UIButton!
@@ -18,7 +19,7 @@ class ViewController: UIViewController, UIAlertViewDelegate {
1819
@IBOutlet weak var btn7:UIButton!
1920
@IBOutlet weak var btn8:UIButton!
2021
@IBOutlet weak var label:UILabel!
21-
let socket = SocketIOClient(socketURL: NSURL(string:"http://localhost:8900")!)
22+
let socket = SocketIOClient(socketURL: URL(string:"http://localhost:8900")!)
2223
var name: String?
2324
var resetAck: SocketAckEmitter?
2425

@@ -31,11 +32,11 @@ class ViewController: UIViewController, UIAlertViewDelegate {
3132
let grad = CAGradientLayer()
3233
grad.frame = self.view.bounds
3334

34-
let colors = [UIColor(red: 127, green: 0, blue: 127, alpha: 1).CGColor,
35-
UIColor(red: 0, green: 0, blue: 0, alpha: 1).CGColor]
35+
let colors = [UIColor(red: 127, green: 0, blue: 127, alpha: 1).cgColor,
36+
UIColor(red: 0, green: 0, blue: 0, alpha: 1).cgColor]
3637

3738
grad.colors = colors
38-
view.layer.insertSublayer(grad, atIndex: 0)
39+
view.layer.insertSublayer(grad, at: 0)
3940
}
4041

4142
func addHandlers() {
@@ -51,13 +52,13 @@ class ViewController: UIViewController, UIAlertViewDelegate {
5152
}
5253

5354
socket.on("playerMove") {[weak self] data, ack in
54-
if let name = data[0] as? String, x = data[1] as? Int, y = data[2] as? Int {
55+
if let name = data[0] as? String, let x = data[1] as? Int, let y = data[2] as? Int {
5556
self?.handlePlayerMove(name, coord: (x, y))
5657
}
5758
}
5859

5960
socket.on("win") {[weak self] data, ack in
60-
if let name = data[0] as? String, typeDict = data[1] as? NSDictionary {
61+
if let name = data[0] as? String, let typeDict = data[1] as? NSDictionary {
6162
self?.handleWin(name, type: typeDict)
6263
}
6364
}
@@ -86,10 +87,10 @@ class ViewController: UIViewController, UIAlertViewDelegate {
8687
exit(0)
8788
}
8889

89-
socket.onAny {print("Got event: \($0.event), with items: \($0.items)")}
90+
socket.onAny {print("Got event: \($0.event), with items: \($0.items!)")}
9091
}
9192

92-
@IBAction func btnClicked(btn: UIButton) {
93+
@IBAction func btnClicked(_ btn: UIButton) {
9394
let coord:(x: Int, y: Int)
9495

9596
switch btn.tag {
@@ -118,7 +119,7 @@ class ViewController: UIViewController, UIAlertViewDelegate {
118119
socket.emit("playerMove", coord.x, coord.y)
119120
}
120121

121-
func drawWinLine(type: NSDictionary) {
122+
func drawWinLine(_ type: NSDictionary) {
122123
let winType = type["type"] as! String
123124
let to: CGPoint
124125
let from: CGPoint
@@ -137,8 +138,8 @@ class ViewController: UIViewController, UIAlertViewDelegate {
137138
to = btn6.center
138139
from = btn8.center
139140
default:
140-
to = CGPointMake(0.0, 0.0)
141-
from = CGPointMake(0.0, 0.0)
141+
to = CGPoint(x: 0.0, y: 0.0)
142+
from = CGPoint(x: 0.0, y: 0.0)
142143
}
143144
} else if winType == "col" {
144145
let row = type["num"] as! Int
@@ -154,8 +155,8 @@ class ViewController: UIViewController, UIAlertViewDelegate {
154155
to = btn2.center
155156
from = btn8.center
156157
default:
157-
to = CGPointMake(0.0, 0.0)
158-
from = CGPointMake(0.0, 0.0)
158+
to = CGPoint(x: 0.0, y: 0.0)
159+
from = CGPoint(x: 0.0, y: 0.0)
159160
}
160161
} else {
161162
let coord = type["coord"] as! NSDictionary
@@ -176,24 +177,24 @@ class ViewController: UIViewController, UIAlertViewDelegate {
176177
to = btn2.center
177178
from = btn6.center
178179
default:
179-
to = CGPointMake(0.0, 0.0)
180-
from = CGPointMake(0.0, 0.0)
180+
to = CGPoint(x: 0.0, y: 0.0)
181+
from = CGPoint(x: 0.0, y: 0.0)
181182
}
182183
}
183184

184185
let path = UIBezierPath()
185-
path.moveToPoint(from)
186-
path.addLineToPoint(to)
186+
path.move(to: from)
187+
path.addLine(to: to)
187188

188189
let shapeLayer = CAShapeLayer()
189-
shapeLayer.path = path.CGPath
190-
shapeLayer.strokeColor = UIColor.whiteColor().CGColor
190+
shapeLayer.path = path.cgPath
191+
shapeLayer.strokeColor = UIColor.white.cgColor
191192
shapeLayer.lineWidth = 3.0
192-
shapeLayer.fillColor = UIColor.clearColor().CGColor
193+
shapeLayer.fillColor = UIColor.clear.cgColor
193194
view.layer.addSublayer(shapeLayer)
194195
}
195196

196-
func handleCurrentTurn(name: String) {
197+
func handleCurrentTurn(_ name: String) {
197198
if name == self.name! {
198199
label.text = "Your turn!"
199200
} else {
@@ -206,59 +207,59 @@ class ViewController: UIViewController, UIAlertViewDelegate {
206207
}
207208

208209
func handleGameReset() {
209-
btn0.setTitle("-", forState: UIControlState.Normal)
210-
btn1.setTitle("-", forState: UIControlState.Normal)
211-
btn2.setTitle("-", forState: UIControlState.Normal)
212-
btn3.setTitle("-", forState: UIControlState.Normal)
213-
btn4.setTitle("-", forState: UIControlState.Normal)
214-
btn5.setTitle("-", forState: UIControlState.Normal)
215-
btn6.setTitle("-", forState: UIControlState.Normal)
216-
btn7.setTitle("-", forState: UIControlState.Normal)
217-
btn8.setTitle("-", forState: UIControlState.Normal)
210+
btn0.setTitle("-", for: UIControlState())
211+
btn1.setTitle("-", for: UIControlState())
212+
btn2.setTitle("-", for: UIControlState())
213+
btn3.setTitle("-", for: UIControlState())
214+
btn4.setTitle("-", for: UIControlState())
215+
btn5.setTitle("-", for: UIControlState())
216+
btn6.setTitle("-", for: UIControlState())
217+
btn7.setTitle("-", for: UIControlState())
218+
btn8.setTitle("-", for: UIControlState())
218219

219-
btn0.enabled = true
220-
btn1.enabled = true
221-
btn2.enabled = true
222-
btn3.enabled = true
223-
btn4.enabled = true
224-
btn5.enabled = true
225-
btn6.enabled = true
226-
btn7.enabled = true
227-
btn8.enabled = true
220+
btn0.isEnabled = true
221+
btn1.isEnabled = true
222+
btn2.isEnabled = true
223+
btn3.isEnabled = true
224+
btn4.isEnabled = true
225+
btn5.isEnabled = true
226+
btn6.isEnabled = true
227+
btn7.isEnabled = true
228+
btn8.isEnabled = true
228229

229230
view.layer.sublayers?.removeLast()
230231
label.text = "Waiting for Opponent"
231232
}
232233

233-
func handlePlayerMove(name: String, coord: (Int, Int)) {
234+
func handlePlayerMove(_ name: String, coord: (Int, Int)) {
234235
switch coord {
235236
case (0, 0):
236-
btn0.setTitle(name, forState: UIControlState.Disabled)
237-
btn0.enabled = false
237+
btn0.setTitle(name, for: UIControlState.disabled)
238+
btn0.isEnabled = false
238239
case (0, 1):
239-
btn1.setTitle(name, forState: UIControlState.Disabled)
240-
btn1.enabled = false
240+
btn1.setTitle(name, for: UIControlState.disabled)
241+
btn1.isEnabled = false
241242
case (0, 2):
242-
btn2.setTitle(name, forState: UIControlState.Disabled)
243-
btn2.enabled = false
243+
btn2.setTitle(name, for: UIControlState.disabled)
244+
btn2.isEnabled = false
244245
case (1, 0):
245-
btn3.setTitle(name, forState: UIControlState.Disabled)
246-
btn3.enabled = false
246+
btn3.setTitle(name, for: UIControlState.disabled)
247+
btn3.isEnabled = false
247248
case (1, 1):
248-
btn4.setTitle(name, forState: UIControlState.Disabled)
249-
btn4.enabled = false
249+
btn4.setTitle(name, for: UIControlState.disabled)
250+
btn4.isEnabled = false
250251
case (1, 2):
251-
btn5.setTitle(name, forState: UIControlState.Disabled)
252-
btn5.enabled = false
252+
btn5.setTitle(name, for: UIControlState.disabled)
253+
btn5.isEnabled = false
253254
case (2, 0):
254-
btn6.setTitle(name, forState: UIControlState.Disabled)
255-
btn6.enabled = false
255+
btn6.setTitle(name, for: UIControlState.disabled)
256+
btn6.isEnabled = false
256257
case (2, 1):
257-
btn7.setTitle(name, forState: UIControlState.Disabled)
258-
btn7.enabled = false
258+
btn7.setTitle(name, for: UIControlState.disabled)
259+
btn7.isEnabled = false
259260
case (2, 2):
260-
btn8.setTitle(name, forState: UIControlState.Disabled)
261-
btn8.enabled = false
261+
btn8.setTitle(name, for: UIControlState.disabled)
262+
btn8.isEnabled = false
262263
default:
263264
return
264265
}
@@ -272,12 +273,12 @@ class ViewController: UIViewController, UIAlertViewDelegate {
272273
}
273274
}
274275

275-
func handleWin(name: String, type: NSDictionary) {
276+
func handleWin(_ name: String, type: NSDictionary) {
276277
label.text = "Player \(name) won!"
277278
drawWinLine(type)
278279
}
279280

280-
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
281+
func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) {
281282
if buttonIndex == 0 {
282283
resetAck?.with(false)
283284
} else {

0 commit comments

Comments
 (0)