Swift: dynamically creating and assigning delegates

210 Views Asked by At

MKMapView's delegate property is defined as so in swift:

@IBOutlet weak open var delegate: MKMapViewDelegate?.

If I had to dynamically create map views for each item in an array whose length/count is unknown beforehand, how I dynamically assign a unique delegate instance to each one of the maps without keeping a class variable for each delegate (since we don't know the count of items in the array). Is there something similar to Obj-C's __Strong ?

Update: I could have a class array to which I add each delegate, but still, are there any other approaches, which are more inline for example by using __Strong, if there is such a thing in Swift

1

There are 1 best solutions below

3
On BEST ANSWER

how I dynamically assign a unique delegate instance to each one of the maps without keeping a class variable for each delegate

There's no need for a unique delegate object for each map view. Delegate methods typically get a reference to the delegator as their first parameter, so the delegate can easily tell which map view is sending the message.