mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
28 lines
795 B
Swift
28 lines
795 B
Swift
import UIKit
|
|
|
|
// UIImage is convertible to and from DatabaseValue.
|
|
extension UIImage : DatabaseValueConvertible {
|
|
/// Returns a value that can be stored in the database.
|
|
public var databaseValue: DatabaseValue {
|
|
if let data = UIImagePNGRepresentation(self) {
|
|
return data.databaseValue
|
|
} else {
|
|
return .Null
|
|
}
|
|
}
|
|
|
|
/**
|
|
Returns an UIImage initialized from *databaseValue*, if possible.
|
|
|
|
- parameter databaseValue: A DatabaseValue.
|
|
- returns: An optional UIImage.
|
|
*/
|
|
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
|
if let data = NSData.fromDatabaseValue(databaseValue) {
|
|
return self.init(data: data)
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
}
|