-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhoto.swift
42 lines (34 loc) · 1.21 KB
/
Photo.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Photo.swift
// VirtualTouristApp
//
// Created by Sean Perez on 9/4/16.
// Copyright © 2016 SeanPerez. All rights reserved.
//
import Foundation
import CoreData
import UIKit
class Photo: NSManagedObject {
override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
init(dictionary: [String:AnyObject], context: NSManagedObjectContext) {
let entity = NSEntityDescription.entity(forEntityName: "Photo", in: context)!
super.init(entity: entity, insertInto: context)
id = dictionary["id"] as! String
imageUrl = dictionary["url_m"] as! String
imageData = nil
}
static func photosFromResult(_ result: AnyObject, context: NSManagedObjectContext) -> [Photo] {
var photos = [Photo]()
if let photosResult = result["photos"] as? NSDictionary {
if let photosArray = photosResult["photo"] as? [[String:AnyObject]] {
for dict in photosArray {
let photo = Photo(dictionary: dict, context: context)
photos.append(photo)
}
}
}
return photos
}
}