Sfoglia il codice sorgente

Merge pull request #52 from norio-nomura/fix-deprecated-warnings

Fix deprecated warnings on Swift 5
Norio Nomura 5 anni fa
parent
commit
e89f5408cf

+ 1 - 1
Sources/Base32/Base16.swift

@@ -30,7 +30,7 @@ import Foundation
 
 public func base16Encode(_ data: Data, uppercase: Bool = true) -> String {
     return data.withUnsafeBytes {
-        base16encode(UnsafeRawPointer($0), data.count, uppercase)
+        base16encode($0.baseAddress!, $0.count, uppercase)
     }
 }
 

+ 2 - 2
Sources/Base32/Base32.swift

@@ -32,13 +32,13 @@ import Foundation
 
 public func base32Encode(_ data: Data) -> String {
     return data.withUnsafeBytes {
-        base32encode(UnsafeRawPointer($0), data.count, alphabetEncodeTable)
+        base32encode($0.baseAddress!, $0.count, alphabetEncodeTable)
     }
 }
 
 public func base32HexEncode(_ data: Data) -> String {
     return data.withUnsafeBytes {
-        base32encode(UnsafeRawPointer($0), data.count, extendedHexAlphabetEncodeTable)
+        base32encode($0.baseAddress!, $0.count, extendedHexAlphabetEncodeTable)
     }
 }
 

+ 1 - 1
Sources/Base32/StringExtension.swift

@@ -32,7 +32,7 @@ extension String {
     /// Data never nil
     internal var dataUsingUTF8StringEncoding: Data {
         return utf8CString.withUnsafeBufferPointer {
-            return Data(bytes: $0.dropLast().map { UInt8.init($0) })
+            return Data($0.dropLast().map { UInt8.init($0) })
         }
     }
     

+ 22 - 0
Sources/Base32/shim.swift

@@ -1,3 +1,5 @@
+import Foundation
+
 #if !swift(>=4.2)
 extension Collection {
     public func firstIndex(
@@ -7,3 +9,23 @@ extension Collection {
     }
 }
 #endif
+
+#if swift(>=4.2)
+#if !compiler(>=5)
+extension Data {
+    func withUnsafeBytes<Result>(_ apply: (UnsafeRawBufferPointer) throws -> Result) rethrows -> Result {
+        return try withUnsafeBytes {
+            try apply(UnsafeRawBufferPointer(start: $0, count: count))
+        }
+    }
+}
+#endif
+#else
+extension Data {
+    func withUnsafeBytes<Result>(_ apply: (UnsafeRawBufferPointer) throws -> Result) rethrows -> Result {
+        return try withUnsafeBytes {
+            try apply(UnsafeRawBufferPointer(start: $0, count: count))
+        }
+    }
+}
+#endif