title: Realm map clustering
body: <p>To create your own data to present in <code>realm map</code> you need Model which looks like from example : </p>
  
  <pre><code>public class ABFRestaurantObject: Object {
      public dynamic var businessId: String?
      public dynamic var name: String?
      public dynamic var address: String?
      public dynamic var city: String?
      public dynamic var state: String?
      public dynamic var postalCode: String?
      public dynamic var latitude: Double = 37.7859547
      public dynamic var longitude: Double = -122.4024658
      public dynamic var phoneNumber: String?
      public let violations = List&lt;ABFViolationObject&gt;()
      public let inspections = List&lt;ABFInspectionObject&gt;()
  
      override public static func primaryKey() -&gt; String? {
          return "businessId"
      }
  }
  </code></pre>
  
  <p>What means this <code>primaryKey</code> ? Then how could I load my own data into it ? Of course omitting fact that you have to create your own model with custom propertiese ? </p>
  
  <p>Thanks in advance! </p>
  
  <h2>EDIT</h2>
  
  <p>I am using Realm map kit clustering</p>
  
  <p>I've created model :</p>
  
  <pre><code>class Test: Object {
  
     public dynamic var id = 0
     public dynamic var latitude = 45.0889
     public dynamic var longitude = 54.1565
  
  override static func primaryKey() -&gt; String? {
      return "id"
  }
  
  
  }
  </code></pre>
  
  <p>Then in my map controller I've added following functions and declarations : </p>
  
  <pre><code>var positions = try! Realm().objects(Test.self)
      var position:Test!
  
  
  override func viewDidLoad() {
          super.viewDidLoad()
          addNewVehicle()
          populateMap()
      }
  
  func addNewPosition() {
      let realm = try! Realm() // 1
  
      try! realm.write { // 2
          let newPos = Test() // 3
  
          newPos.latitude = 50.060363
          newPos.longitude = 19.939983
          realm.add(newPos) // 5
          self.position = newPos // 6
      }
  }
  
  func populateMap() {
      mapView.removeAnnotations(mapView.annotations) // 1
  
      let positions = try! Realm().objects(Test.self) // 2
  
      // Create annotations for each one
      for pos in positions { // 3
          let coord = CLLocationCoordinate2D(latitude: pos.latitude, longitude: pos.longitude);
          let pin = MapPin(coordinate: coord, title: "asd", subtitle: "asd")
          mapView.addAnnotation(pin) // 4
      }
  }
  </code></pre>
  
  <p>And at the end simple class fro creating pins : </p>
  
  <pre><code>class MapPin : NSObject, MKAnnotation {
      var coordinate: CLLocationCoordinate2D
      var title: String?
      var subtitle: String?
  
      init(coordinate: CLLocationCoordinate2D, title: String, subtitle: String) {
          self.coordinate = coordinate
          self.title = title
          self.subtitle = subtitle
      }
  }
  </code></pre>
  
  <p>I would like to create few random pins and see if clustring works. 
  Atm i am getting an error in line : </p>
  
  <pre><code>safeObject-&gt;_coordinate = coordinate;
  </code></pre>
  
  <p>Thread 9: EXC_BAD_ACCESS(code=1,address=0x40)</p>
  
  <pre><code>po positions
  Results&lt;Test&gt; (
      [0] Test {
          latitude = 50.060363;
          longitude = 19.939983;
      },
      [1] Test {
          latitude = 50.060363;
          longitude = 19.939983;
      },
      [2] Test {
          latitude = 50.060363;
          longitude = 19.939983;
      }
  )
  </code></pre>
  
  <p>Then I've added as well to my <code>AppDelegate.swift</code> to the method <code>didFinishLaunchingWithOptions</code> :</p>
  
  <pre><code> let config = RLMRealmConfiguration.default()
          config.schemaVersion = 1
          config.migrationBlock = { (migration, oldSchemaVersion) in
          }
          RLMRealmConfiguration.setDefault(config)
  </code></pre>
  
  <p>Error: "Primary key property 'Test.id' has duplicate values after migration." </p>