mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Blob.init(dataNoCopy:)
This commit is contained in:
1 parent
b686e1fe91
commit
236aff297e
2 files changed
+32
-5
No files matched your search
@@ -22,11 +22,38 @@ extension NSData : DatabaseValueConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// Blob support for NSData
|
||||
extension Blob {
|
||||
/// Creates a Blob from NSData. Returns nil if and only if *data* is nil or
|
||||
/// zero-length (SQLite can't store empty blobs).
|
||||
|
||||
/**
|
||||
Creates a Blob from NSData.
|
||||
|
||||
Returns nil if and only if *data* is nil or zero-length (SQLite can't store
|
||||
empty blobs).
|
||||
|
||||
The data is *copied*.
|
||||
|
||||
- parameter data: An NSData
|
||||
*/
|
||||
public init?(data: NSData?) {
|
||||
// SQLite can't store empty blobs
|
||||
if let data = data where data.length > 0 {
|
||||
impl = NSDataImpl(data: data.copy() as! NSData)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a Blob from NSData.
|
||||
|
||||
Returns nil if and only if *data* is nil or zero-length (SQLite can't store
|
||||
empty blobs).
|
||||
|
||||
The data is *not copied*.
|
||||
|
||||
- parameter data: An NSData
|
||||
*/
|
||||
public init?(dataNoCopy data: NSData?) {
|
||||
if let data = data where data.length > 0 {
|
||||
impl = NSDataImpl(data: data)
|
||||
} else {
|
||||
@@ -45,7 +72,7 @@ extension Blob {
|
||||
}
|
||||
}
|
||||
|
||||
/// A BlobImpl that stores NSData
|
||||
/// A BlobImpl that stores NSData without copying it.
|
||||
private struct NSDataImpl : BlobImpl {
|
||||
let data: NSData
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ Release Notes
|
||||
|
||||
- `DatabaseDate` has been removed.
|
||||
- `DatabaseValueConvertible`: `init?(databaseValue:)` has been replaced by `static func fromDatabaseValue(_) -> Self?`
|
||||
- `Blob.init(_)` has been renamed `Blob.init(data:)`
|
||||
- `Blob.init(_)` has been replaced with `Blob.init(data:)` and `Blob.init(dataNoCopy:)`.
|
||||
- `RowModel.edited` has been renamed `RowModel.databaseEdited`.
|
||||
- `RowModel.databaseTable` has been replaced with `RowModel.databaseTableName()` which returns a String.
|
||||
- `RowModel.setDatabaseValue(_:forColumn:)` has been removed. Use and override `RowModel.updateFromRow(_)` instead.
|
||||
|
||||
Reference in new issue
Block a user