Assume NSUUID.fromDatabaseValue no longer needs special care in Release configuration, since we target Xcode 10+ now

This commit is contained in:
Gwendal Roué committed 2019-02-28 13:28:06 +01:00
1 parent 22edb91796
commit 0fe7db2694
1 file changed
+9 -14
+9 -14
View File
@@ -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<UInt8>.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: