From 236aff297e4fd94ff9d1e001a7dbb04f39ec62aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 6 Sep 2015 17:39:54 +0200 Subject: [PATCH] Blob.init(dataNoCopy:) --- GRDB/Foundation/NSData.swift | 35 +++++++++++++++++++++++++++++++---- RELEASE_NOTES.md | 2 +- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/GRDB/Foundation/NSData.swift b/GRDB/Foundation/NSData.swift index fd3f11758..009c9ecf1 100644 --- a/GRDB/Foundation/NSData.swift +++ b/GRDB/Foundation/NSData.swift @@ -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 diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f87a6869f..ed09379a1 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -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.