mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
26 lines
748 B
Swift
26 lines
748 B
Swift
import Foundation
|
|
|
|
/// NSData is convertible to and from DatabaseValue.
|
|
extension NSData: DatabaseValueConvertible {
|
|
|
|
/// Returns a BLOB database value.
|
|
public var databaseValue: DatabaseValue {
|
|
(self as Data).databaseValue
|
|
}
|
|
|
|
/// Returns an `NSData` from the specified database value.
|
|
///
|
|
/// If the database value contains a data blob, returns it.
|
|
///
|
|
/// If the database value contains a string, returns this string converted
|
|
/// to UTF8 data.
|
|
///
|
|
/// Otherwise, returns nil.
|
|
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {
|
|
guard let data = Data.fromDatabaseValue(dbValue) else {
|
|
return nil
|
|
}
|
|
return cast(data)
|
|
}
|
|
}
|