abfrealmmapview

Introduction

Welcome to the documentation for ABFRealmMapView, a library that allows you to integrate RealM-based data with MapKit on iOS using a convenient and flexible approach.

Requirements

  • iOS 10.0 or later
  • Xcode 11.0 or later
  • Swift 4.2 or later
  • RealM 2.0 or later

Installation

ABFRealmMapView can be installed through the CocoaPods dependency manager. To install it, add the following line to your Podfile:


pod 'ABFRealmMapView'

Then run the following command:


pod install

Usage

To get started with ABFRealmMapView, follow the steps below:

  1. Import ABFRealmMapView into your project:

  2. import ABFRealmMapView

  3. Create an instance of ABFRealmMapView and configure it:
  4. 
        let realmMapView = ABFRealmMapView(frame: view.bounds, style: .plain)
        realmMapView.realmConfiguration = yourRealmConfiguration
        realmMapView.realmObjectClassName = "YourRealmObject"
      
  5. Optional: Customize the map view appearance:
  6. 
        realmMapView.clusterTitle = "Cluster"
        realmMapView.showSingleObjectAnnotation = true
      
  7. Set the selected object block:
  8. 
        realmMapView.selectedObjectBlock = { [weak self] object in
          // Handle selected object
        }
      
  9. Optional: Set up a predicate to filter displayed objects:
  10. 
        realmMapView.predicateBlock = { object in
          // Filter logic for objects
          return true // or false if object should not be displayed
        }
      
  11. Add the realmMapView as a subview to your view:

  12. view.addSubview(realmMapView)

Methods

Here are the main methods available in ABFRealmMapView:

  • refreshMapView: Refreshes the map view based on the current data in the Realm database.
  • selectedObjectChanged(_:): Notifies the ABFRealmMapView that the selected object has changed.
  • regionForAnnotations(_:): Returns a region that fits the given annotations on the map view.

Delegate

To be notified of certain events and to customize behavior, you can implement the ABFRealmMapViewDelegate. The following methods are available:

  • realmMapView(_:didSelectCluster:with:) -> Bool: Called when a cluster is selected.
  • realmMapView(_:didSelectSingleObject:with:) -> Bool: Called when a single object is selected.
  • realmMapView(_:didDeselectSingleObject:with:) -> Bool: Called when a selected object is deselected.
  • realmMapView(_:didDeselectCluster:with:) -> Bool: Called when a selected cluster is deselected.

Conclusion

Congratulations! You should now have a good understanding of how to integrate ABFRealmMapView into your iOS application. If you have any further questions or issues, feel free to consult the official GitHub repository or reach out to the developer community.