I want to convert a custom MKAnnotationView
written in Obj-C to Swift and I am having an error when I want to initWithAnnotation.
Below I will provide both the ObjC and The Swift code:
class JPThumbnailAnnotationView: MKAnnotationView,JPThumbnailAnnotationViewProtocol {
var coordinate :CLLocationCoordinate2D
var imageView : UIImageView
var titleLabel : UILabel
var subtitleLabel : UILabel
var disclosureBlock : JPThumbnail.SequencerNext
func initWithAnnotation(annotation : MKAnnotation) {
self = MKAnnotationView(annotation: annotation, reuseIdentifier: kJPSThumbnailAnnotationViewReuseID) //HERE IS WHERE I GET THE ERROR
self.canShowCallout = true
self.frame = CGRectMake(0, 0, kJPSThumbnailAnnotationViewStandardWidth, kJPSThumbnailAnnotationViewStandardHeight)
self.centerOffset = CGPointMake(0, -kJPSThumbnailAnnotationViewVerticalOffset)
}
And the Objective-C version is
- (id)initWithAnnotation:(id<MKAnnotation>)annotation {
self = [super initWithAnnotation:annotation reuseIdentifier:kJPSThumbnailAnnotationViewReuseID];
if (self) {
self.canShowCallout = NO;
self.frame = CGRectMake(0, 0, kJPSThumbnailAnnotationViewStandardWidth, kJPSThumbnailAnnotationViewStandardHeight);
self.backgroundColor = [UIColor clearColor];
self.centerOffset = CGPointMake(0, -kJPSThumbnailAnnotationViewVerticalOffset);
_state = JPSThumbnailAnnotationViewStateCollapsed;
[self setupView];
}
return self;
}
The error I am getting is:Can not assign self in a method
IS there a way I can still assign self in my case or should I just create a variable of type MKAnnotationView assign it to the result of the initialiser and change the return type of the function OR is there another way I can do this?