Skip to content

Commit aa368f9

Browse files
committed
don't force unwrap in fixutf
1 parent 28ae7a8 commit aa368f9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

SocketIOClientSwift/SocketFixUTF8.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
import Foundation
2727

2828
func fixDoubleUTF8(inout name: String) {
29-
let utf8 = name.dataUsingEncoding(NSISOLatin1StringEncoding)!
30-
let latin1 = NSString(data: utf8, encoding: NSUTF8StringEncoding)!
31-
name = latin1 as String
29+
if let utf8 = name.dataUsingEncoding(NSISOLatin1StringEncoding),
30+
latin1 = NSString(data: utf8, encoding: NSUTF8StringEncoding) {
31+
name = latin1 as String
32+
}
3233
}
3334

3435
func doubleEncodeUTF8(inout str: String) {
35-
let latin1 = str.dataUsingEncoding(NSUTF8StringEncoding)!
36-
let utf8 = NSString(data: latin1, encoding: NSISOLatin1StringEncoding)!
37-
str = utf8 as String
36+
if let latin1 = str.dataUsingEncoding(NSUTF8StringEncoding),
37+
utf8 = NSString(data: latin1, encoding: NSISOLatin1StringEncoding) {
38+
str = utf8 as String
39+
}
3840
}

0 commit comments

Comments
 (0)