Skip to content

v10.47.0

Compare
Choose a tag to compare
@github-actions github-actions released this 13 Feb 15:34
· 129 commits to master since this release

Enhancements

  • Added initial support for geospatial queries on points. There is no new dedicated type to store Geospatial points, instead points should be stored as (GeoJson-shaped) embedded object, as the example below:
    public class Location: EmbeddedObject {
      @Persisted private var coordinates: List<Double>
      @Persisted private var type: String = "Point"
    
      public var latitude: Double { return coordinates[1] }
      public var longitude: Double { return coordinates[0] }
    
      convenience init(_ latitude: Double, _ longitude: Double) {
          self.init()
          // Longitude comes first in the coordinates array of a GeoJson document
          coordinates.append(objectsIn: [longitude, latitude])
      }
    }
    Geospatial queries (geoWithin) can only be executed on such a type of objects and will throw otherwise. The queries can be used to filter objects whose points lie within a certain area, using the following pre-established shapes (GeoBox, GeoPolygon, GeoCircle).
    class Person: Object {
      @Persisted var name: String
      @Persisted var location: Location? // GeoJson embedded object
    }
    
    let realm = realmWithTestPath()
    try realm.write {
      realm.add(PersonLocation(name: "Maria", location: Location(latitude: 55.6761, longitude: 12.5683)))
    }
    
    let shape = GeoBox(bottomLeft: (55.6281, 12.0826), topRight: (55.6762, 12.5684))!
    let locations = realm.objects(PersonLocation.self).where { $0.location.geoWithin(shape) })
    A filter or NSPredicate can be used as well to perform a Geospatial query.
    let shape = GeoPolygon(outerRing: [(-2, -2), (-2, 2), (2, 2), (2, -2), (-2, -2)], holes: [[(0, 0), (1, 1), (-1, 1), (0, 0)]])!
    let locations = realm.objects(PersonLocation.self).filter("location IN %@", shape)
    
    let locations = realm.objects(PersonLocation.self).filter(NSPredicate(format: "location IN %@", shape))

Compatibility

  • Realm Studio: 14.0.1 or later.
  • APIs are backwards compatible with all previous releases in the 10.x.y series.
  • Carthage release for Swift is built with Xcode 15.2.0.
  • CocoaPods: 1.10 or later.
  • Xcode: 14.2-15.2.0.

Internal

  • Migrated Release pipelines to Github Actions.