Skip to content

Commit

Permalink
Fix: Resolve deprecation warnings for swift 4.1 (#33)
Browse files Browse the repository at this point in the history
Resolved deprecation warnings for swift 4.1 and added swift4.1 checks.
  • Loading branch information
ShihabMehboob authored and KyeMaloy97 committed Apr 13, 2018
1 parent dba2abd commit 5b94fe8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Sources/KituraWebSocket/WSFrame.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ struct WSFrame {
payloadLengthUInt16 = CFSwapInt16HostToBig(tempPayloadLengh)
#endif
let asBytes = UnsafeMutablePointer(&payloadLengthUInt16)
(UnsafeMutableRawPointer(mutating: bytes)+length+1).copyBytes(from: asBytes, count: 2)
#if swift(>=4.1)
(UnsafeMutableRawPointer(mutating: bytes)+length+1).copyMemory(from: asBytes, byteCount: 2)
#else
(UnsafeMutableRawPointer(mutating: bytes)+length+1).copyBytes(from: asBytes, count: 2)
#endif
length += 3
} else {
bytes[1] = 127
Expand All @@ -62,7 +66,11 @@ struct WSFrame {
payloadLengthUInt32 = CFSwapInt32HostToBig(tempPayloadLengh)
#endif
let asBytes = UnsafeMutablePointer(&payloadLengthUInt32)
(UnsafeMutableRawPointer(mutating: bytes)+length+5).copyBytes(from: asBytes, count: 4)
#if swift(>=4.1)
(UnsafeMutableRawPointer(mutating: bytes)+length+5).copyMemory(from: asBytes, byteCount: 4)
#else
(UnsafeMutableRawPointer(mutating: bytes)+length+5).copyBytes(from: asBytes, count: 4)
#endif
length += 9
}
buffer.append(bytes, length: length)
Expand Down
6 changes: 5 additions & 1 deletion Sources/KituraWebSocket/WSFrameParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ struct WSFrameParser {

if bytesConsumed > 0 {
if length - from - bytesConsumed >= maskSize {
UnsafeMutableRawPointer(mutating: mask).copyBytes(from: bytes+from+bytesConsumed, count: maskSize)
#if swift(>=4.1)
UnsafeMutableRawPointer(mutating: mask).copyMemory(from: bytes+from+bytesConsumed, byteCount: maskSize)
#else
UnsafeMutableRawPointer(mutating: mask).copyBytes(from: bytes+from+bytesConsumed, count: maskSize)
#endif
bytesConsumed += maskSize
}
else {
Expand Down

0 comments on commit 5b94fe8

Please sign in to comment.