-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPin+CoreDataClass.swift
More file actions
50 lines (39 loc) · 1.62 KB
/
Pin+CoreDataClass.swift
File metadata and controls
50 lines (39 loc) · 1.62 KB
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
42
43
44
45
46
47
48
49
50
//
// Pin+CoreDataClass.swift
// Virtual Tourist
//
// Created by Alessandro Bellotti on 24/08/17.
// Copyright © 2017 Alessandro Bellotti. All rights reserved.
//
import Foundation
import MapKit
import CoreData
@objc(Pin)
public class Pin: NSManagedObject {
// MARK: Initializer
// In Swift, superclass initializers are not available to subclasses, so it is necessary to include this initializer and call the superclass' implementation of it.
override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
convenience init(latitude: Double, longitude: Double, title : String, subtitle: String, context: NSManagedObjectContext) {
// An EntityDescription is an object that has access to all
// the information you provided in the Entity part of the model
// you need it to create an instance of this class.
if let ent = NSEntityDescription.entity(forEntityName: "Pin", in: context) {
self.init(entity: ent, insertInto: context)
self.latitude = latitude;
self.longitude = longitude
self.title = title
self.subtitle = subtitle
self.numOfPages = 0
} else {
fatalError("Unable to find Entity name!")
}
}
var coordinate: CLLocationCoordinate2D {
return CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
}
var sharedContext: NSManagedObjectContext {
return CoreDataController.sharedInstance().managedObjectContext
}
}