2017-07-08 02:49:16 +02:00
|
|
|
//
|
|
|
|
// Attachment+Database.swift
|
|
|
|
// Database
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 7/4/17.
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2017-07-12 22:25:10 +02:00
|
|
|
import Data
|
2017-07-08 02:49:16 +02:00
|
|
|
|
|
|
|
extension Attachment {
|
|
|
|
|
2017-07-12 22:25:10 +02:00
|
|
|
init?(databaseDictionary d: [String: Any]) {
|
2017-07-08 02:49:16 +02:00
|
|
|
|
|
|
|
guard let url = d[DatabaseKey.url] as? String else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
let mimeType = d[DatabaseKey.mimeType] as? String
|
|
|
|
let title = d[DatabaseKey.title] as? String
|
2017-07-12 22:25:10 +02:00
|
|
|
let sizeInBytes = d[DatabaseKey.sizeInBytes] as? Int
|
2017-07-08 02:49:16 +02:00
|
|
|
let durationInSeconds = d[DatabaseKey.durationInSeconds] as? Int
|
|
|
|
|
2017-07-12 22:25:10 +02:00
|
|
|
self.init(url: url, mimeType: mimeType, title: title, sizeInBytes: sizeInBytes, durationInSeconds: durationInSeconds)
|
2017-07-08 02:49:16 +02:00
|
|
|
}
|
|
|
|
|
2017-07-12 22:25:10 +02:00
|
|
|
static func attachments(with plist: [Any]) -> [Attachment]? {
|
2017-07-08 02:49:16 +02:00
|
|
|
|
|
|
|
return plist.flatMap{ (oneDictionary) -> Attachment? in
|
|
|
|
if let d = oneDictionary as? [String: Any] {
|
|
|
|
return Attachment(databaseDictionary: d)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|