Jacek Bednarczyk
Jacek Bednarczyk

Reputation: 13

How to add extra property in MKAnnotation swift

I want to add extra property into MKAnnotation in Swift. Now i can use property like title, subtitle or coordinate. I want to add property for example extraTitle to store some text. I don't know how to write some extension :( Can You help me?

Upvotes: 0

Views: 550

Answers (1)

Matt
Matt

Reputation: 430

MKAnnotation is a protocol. You can define a class which implements the protocol properties, and adds anything extra you want.

class MyAnnotation: NSObject,MKAnnotation {
    var coordinate: CLLocationCoordinate2D
    var title: String?
    var subtitle: String?
    var extraTitle: String?
    init(coordinate:CLLocationCoordinate2D) {
        self.coordinate = coordinate
    }
}

Upvotes: 6

Related Questions