mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
DatabaseValue.toAnyObject(), Row.toNSDictionary()
This commit is contained in:
1 parent
c987a0a9af
commit
c8cf0df6e1
2 files changed
+20
-13
No files matched your search
@@ -15,4 +15,22 @@ extension DatabaseValue {
|
||||
}
|
||||
self.init(convertible.databaseValue)
|
||||
}
|
||||
|
||||
/// Converts a DatabaseValue to AnyObject.
|
||||
///
|
||||
/// - returns: NSNull, NSNumber, NSString, or NSData.
|
||||
public func toAnyObject() -> AnyObject {
|
||||
switch storage {
|
||||
case .Null:
|
||||
return NSNull()
|
||||
case .Int64(let int64):
|
||||
return NSNumber(longLong: int64)
|
||||
case .Double(let double):
|
||||
return NSNumber(double: double)
|
||||
case .String(let string):
|
||||
return string as NSString
|
||||
case .Blob(let data):
|
||||
return data
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,22 +30,11 @@ extension Row {
|
||||
/// the value of the leftmost column.
|
||||
///
|
||||
/// - returns: An NSDictionary.
|
||||
public func toDictionary() -> NSDictionary {
|
||||
public func toNSDictionary() -> NSDictionary {
|
||||
var dictionary = [NSObject: AnyObject]()
|
||||
// Reverse so that the result dictionary contains values for the leftmost columns.
|
||||
for (columnName, databaseValue) in reverse() {
|
||||
switch databaseValue.storage {
|
||||
case .Null:
|
||||
dictionary[columnName] = NSNull()
|
||||
case .Int64(let int64):
|
||||
dictionary[columnName] = NSNumber(longLong: int64)
|
||||
case .Double(let double):
|
||||
dictionary[columnName] = NSNumber(double: double)
|
||||
case .String(let string):
|
||||
dictionary[columnName] = string as NSString
|
||||
case .Blob(let data):
|
||||
dictionary[columnName] = data
|
||||
}
|
||||
dictionary[columnName] = databaseValue.toAnyObject()
|
||||
}
|
||||
return dictionary
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user