I am trying to make a simple class that will be used as annotations for mine MKMapView. I am extracting the data that I want to analyze in these annotation objects, and think that it would be nice to initialize the annotation with the dictionary and do all the parsing in this model class, not in UIViewController. It seems I can not get rid of errors related to compilers, although when I try to fix them, another appears.
Currently, getting a property is self.coordinatenot initialized with an implicitly generated call super.init. The call super.init()only creates another error, “Property is self.coordinatenot initialized in super.initcall,” regardless of where I make the call super.init()in the method. Any help could be helpful! Here is what my code looks like now.
import Foundation
import MapKit
class Student: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var title: String
var subtitle: String
init(dictionary: Dictionary<String, AnyObject>) {
if let first = dictionary["firstName"] as? String {
if let last = dictionary["lastName"] as? String {
self.coordinate = CLLocationCoordinate2DMake(dictionary["latitude"] as! Double, dictionary["longitude"] as! Double)
self.title = first + " " + last
if let mediaURL = dictionary["mediaURL"] as? String {
self.subtitle = mediaURL
}
}
}
}
}
source
share