hulab / ClusterKit

An iOS map clustering framework targeting MapKit, Google Maps and Mapbox.
MIT License
512 stars 86 forks source link

Use `clusterManager` in MGLMapView extensions (Carthage & 0.4.0) #67

Closed Max37550 closed 5 years ago

Max37550 commented 5 years ago

Hello,

This issue only happens when using Carthage, it works fine with Cocoapods.

The following snippet doesn't compile with the version 0.4.0, but it did work before. It says it cannot found clusterManager. I have noticed a difference in the framework built by Carthage, MKMapView+ClusterKit.h is in PrivateHeaders but for 0.3.5, it is in Headers.

import ClusterKit
import Mapbox

protocol Foo {
         var selectedAnnotation: MKAnnotation { get }
}

extension MGLMapView: Foo {
    var selectedAnnotation: MKAnnotation {
        return clusterManager.selectedAnnotation
    }
}

Thanks for your help. :)

rabc commented 5 years ago

There is any specific reason for MKMapView+ClusterKit.h to be in Private headers?

maxep commented 5 years ago

Hey!

@Max37550

For Cluster+MapKit with Carthage, you should import the submodule:

import ClusterKit.MapKit

cf. https://github.com/hulab/ClusterKit/wiki/MapKit

Cluster+Mapbox

The MGLMapView+ClusterKit extension is not part of the ClusterKit.framework to respect the interface segregation principle. If you want to use ClusterKit with Mapbox using Carthage I suggest to copy/past the MGLMapView+ClusterKit.{h,m} files to your project. I know this not ideal but I don't want to force the MapBox dependency.

@rabc

MKMapView+ClusterKit.h is private for the same reason, the difference is that MapKit is always available in iOS. To use it, you need to explicitly import it:

Objective-C:
#import <ClusterKit/MKMapView+ClusterKit.h>
Swift:
import ClusterKit.MapKit