From 0fe7db2694afc2f4a449d7355c838726e71fa5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 28 Feb 2019 13:28:06 +0100 Subject: [PATCH] Assume NSUUID.fromDatabaseValue no longer needs special care in Release configuration, since we target Xcode 10+ now --- GRDB/Core/Support/Foundation/UUID.swift | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/GRDB/Core/Support/Foundation/UUID.swift b/GRDB/Core/Support/Foundation/UUID.swift index 20f0f79dc..30b6c3344 100644 --- a/GRDB/Core/Support/Foundation/UUID.swift +++ b/GRDB/Core/Support/Foundation/UUID.swift @@ -19,20 +19,15 @@ extension NSUUID: DatabaseValueConvertible { public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? { switch dbValue.storage { case .blob(let data) where data.count == 16: - // TODO: Simplify now that Xcode 10+ is required. - // The code below works in debug configuration, but crashes in - // release configuration (Xcode 9.4.1) - -// return data.withUnsafeBytes { -// self.init(uuidBytes: $0) -// } - - // Workaround (involves a useless copy) - let buffer = UnsafeMutableBufferPointer.allocate(capacity: 16) - _ = data.copyBytes(to: buffer) - let uuid = self.init(uuidBytes: UnsafePointer(buffer.baseAddress!)) - buffer.deallocate() - return uuid + #if swift(>=5.0) + return data.withUnsafeBytes { + self.init(uuidBytes: $0.bindMemory(to: UInt8.self).baseAddress) + } + #else + return data.withUnsafeBytes { + self.init(uuidBytes: $0) + } + #endif case .string(let string): return self.init(uuidString: string) default: